From patchwork Sun Jan 31 16:49:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naphtali Sprei X-Patchwork-Id: 44121 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 C1D3BB7D6A for ; Mon, 1 Feb 2010 03:59:50 +1100 (EST) Received: from localhost ([127.0.0.1]:48042 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nbd19-0008Vm-8G for incoming@patchwork.ozlabs.org; Sun, 31 Jan 2010 11:51:23 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nbczx-0008Vg-5G for qemu-devel@nongnu.org; Sun, 31 Jan 2010 11:50:09 -0500 Received: from [199.232.76.173] (port=60660 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nbczv-0008VY-SO for qemu-devel@nongnu.org; Sun, 31 Jan 2010 11:50:07 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nbczu-000622-GQ for qemu-devel@nongnu.org; Sun, 31 Jan 2010 11:50:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15995) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nbczu-00061o-4G for qemu-devel@nongnu.org; Sun, 31 Jan 2010 11:50:06 -0500 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 o0VGo3dQ011420 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 31 Jan 2010 11:50:04 -0500 Received: from [10.35.0.60] (dhcp-0-60.tlv.redhat.com [10.35.0.60]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0VGo0uh009184 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 31 Jan 2010 11:50:02 -0500 Message-ID: <4B65B4B7.2030700@redhat.com> Date: Sun, 31 Jan 2010 18:49:59 +0200 From: Naphtali Sprei User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: qemu-devel@nongnu.org X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf , Sheng Yang Subject: [Qemu-devel] [PATCH] block: Enable fall-back to read-only for backing file 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 There's a problem when trying to use an image file based on a read-only image file. Before this patch, qemu fails to open the base image and stop. With this patch, qemu tries to open the backing file with same permissions as the "top" file, but if it fails, qemu tries to open it with read-only permissions. If succeeded it goes on. This fall-back works both for an image file based on a read-only file and also for a read-only file opened with the snapshot attribute/mode (where the real file is the backing file for the snapshot file). Is it better to always open the backing file with read-only mode ? this will be more consistent/predictable ? Or is it better not to fall-back to read-only ? Will a warning message help ? TIA, Naphtali From 4a10750f5c91b1383118e4421f6b8d3ff3e79b2f Mon Sep 17 00:00:00 2001 From: Naphtali Sprei Date: Sun, 31 Jan 2010 18:23:44 +0200 Subject: [PATCH] block: Enable fall-back to read-only for backing file In order to use an image file backed by a read-only file, allow opening the backing file with read-only permission. Signed-off-by: Naphtali Sprei --- block.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index 1919d19..d1b0f3d 100644 --- a/block.c +++ b/block.c @@ -483,6 +483,11 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, back_drv = bdrv_find_format(bs->backing_format); ret = bdrv_open2(bs->backing_hd, backing_filename, open_flags, back_drv); + if (ret < 0) { + open_flags &= ~BDRV_O_RDWR; /* Fall-back to read-only for the backing file */ + ret = bdrv_open2(bs->backing_hd, backing_filename, open_flags, + back_drv); + } bs->backing_hd->read_only = (open_flags & BDRV_O_RDWR) == 0; if (ret < 0) { bdrv_close(bs);