qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] block: Enable fall-back to read-only for backing file
@ 2010-01-31 16:49 Naphtali Sprei
  2010-02-01  8:46 ` [Qemu-devel] " Kevin Wolf
  0 siblings, 1 reply; 7+ messages in thread
From: Naphtali Sprei @ 2010-01-31 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Sheng Yang

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 <nsprei@redhat.com>
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 <nsprei@redhat.com>
---
 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);
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] Re: [PATCH] block: Enable fall-back to read-only for backing file
  2010-01-31 16:49 [Qemu-devel] [PATCH] block: Enable fall-back to read-only for backing file Naphtali Sprei
@ 2010-02-01  8:46 ` Kevin Wolf
  2010-02-01  9:06   ` Christoph Hellwig
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Wolf @ 2010-02-01  8:46 UTC (permalink / raw)
  To: Naphtali Sprei; +Cc: qemu-devel, Sheng Yang

Am 31.01.2010 17:49, schrieb Naphtali Sprei:
> 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 ?

I would love to open them read-only unconditionally, but we can't. It
would break the commit monitor command. I think the read-only fallback
is appropriate for backing files.

Kevin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] Re: [PATCH] block: Enable fall-back to read-only for backing file
  2010-02-01  8:46 ` [Qemu-devel] " Kevin Wolf
@ 2010-02-01  9:06   ` Christoph Hellwig
  2010-02-01  9:25     ` Alexander Graf
  0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2010-02-01  9:06 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: Naphtali Sprei, qemu-devel, Sheng Yang

On Mon, Feb 01, 2010 at 09:46:00AM +0100, Kevin Wolf wrote:
> > Is it better to always open the backing file with read-only mode ? this will be more consistent/predictable ?
> 
> I would love to open them read-only unconditionally, but we can't. It
> would break the commit monitor command. I think the read-only fallback
> is appropriate for backing files.

The clean way would be to require an explicit BACKING_WRITEABLE flag
if we want to commit to it.  But I suspect it's too late to refit that
now.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] Re: [PATCH] block: Enable fall-back to read-only for backing file
  2010-02-01  9:06   ` Christoph Hellwig
@ 2010-02-01  9:25     ` Alexander Graf
  2010-02-01  9:27       ` Christoph Hellwig
  0 siblings, 1 reply; 7+ messages in thread
From: Alexander Graf @ 2010-02-01  9:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Kevin Wolf, Naphtali Sprei, qemu-devel@nongnu.org, Sheng Yang


Am 01.02.2010 um 10:06 schrieb Christoph Hellwig <hch@lst.de>:

> On Mon, Feb 01, 2010 at 09:46:00AM +0100, Kevin Wolf wrote:
>>> Is it better to always open the backing file with read-only mode ?  
>>> this will be more consistent/predictable ?
>>
>> I would love to open them read-only unconditionally, but we can't. It
>> would break the commit monitor command. I think the read-only  
>> fallback
>> is appropriate for backing files.
>
> The clean way would be to require an explicit BACKING_WRITEABLE flag
> if we want to commit to it.  But I suspect it's too late to refit that
> now.

We don't know beforehand if a user will use the commit comnand during  
tje runtime of the vm.

IMHO it'd be best to always open backing files read only and try to  
open them for write access on the commit command. That command can  
then fail gaciously.

Alex
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] Re: [PATCH] block: Enable fall-back to read-only for backing file
  2010-02-01  9:25     ` Alexander Graf
@ 2010-02-01  9:27       ` Christoph Hellwig
  2010-02-01 10:05         ` Alexander Graf
  2010-02-01 12:32         ` Jamie Lokier
  0 siblings, 2 replies; 7+ messages in thread
From: Christoph Hellwig @ 2010-02-01  9:27 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Kevin Wolf, Naphtali Sprei, Christoph Hellwig, Sheng Yang,
	qemu-devel@nongnu.org

On Mon, Feb 01, 2010 at 10:25:52AM +0100, Alexander Graf wrote:
> We don't know beforehand if a user will use the commit comnand during  
> tje runtime of the vm.
> 
> IMHO it'd be best to always open backing files read only and try to  
> open them for write access on the commit command. That command can  
> then fail gaciously.

That's another option.  Basically this means opening another
BlockDriverState for the backing device that is writeable inside
bdrv_commit().

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] Re: [PATCH] block: Enable fall-back to read-only for backing file
  2010-02-01  9:27       ` Christoph Hellwig
@ 2010-02-01 10:05         ` Alexander Graf
  2010-02-01 12:32         ` Jamie Lokier
  1 sibling, 0 replies; 7+ messages in thread
From: Alexander Graf @ 2010-02-01 10:05 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Kevin Wolf, Naphtali Sprei, qemu-devel@nongnu.org, Sheng Yang

Christoph Hellwig wrote:
> On Mon, Feb 01, 2010 at 10:25:52AM +0100, Alexander Graf wrote:
>   
>> We don't know beforehand if a user will use the commit comnand during  
>> tje runtime of the vm.
>>
>> IMHO it'd be best to always open backing files read only and try to  
>> open them for write access on the commit command. That command can  
>> then fail gaciously.
>>     
>
> That's another option.  Basically this means opening another
> BlockDriverState for the backing device that is writeable inside
> bdrv_commit().
>   

Or another function call hook to change the backing device state from RO
to RW.

Alex

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] Re: [PATCH] block: Enable fall-back to read-only for backing file
  2010-02-01  9:27       ` Christoph Hellwig
  2010-02-01 10:05         ` Alexander Graf
@ 2010-02-01 12:32         ` Jamie Lokier
  1 sibling, 0 replies; 7+ messages in thread
From: Jamie Lokier @ 2010-02-01 12:32 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Kevin Wolf, qemu-devel@nongnu.org, Naphtali Sprei, Alexander Graf,
	Sheng Yang

Christoph Hellwig wrote:
> On Mon, Feb 01, 2010 at 10:25:52AM +0100, Alexander Graf wrote:
> > We don't know beforehand if a user will use the commit comnand during  
> > tje runtime of the vm.
> > 
> > IMHO it'd be best to always open backing files read only and try to  
> > open them for write access on the commit command. That command can  
> > then fail gaciously.
> 
> That's another option.  Basically this means opening another
> BlockDriverState for the backing device that is writeable inside
> bdrv_commit().

I'd prefer that.  I like having higher confidence that random bugs in
Qemu are unlikely to accidentally modify precious backing files,
except when I've issued an explicit commit command.

-- Jamie

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-02-01 12:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-31 16:49 [Qemu-devel] [PATCH] block: Enable fall-back to read-only for backing file Naphtali Sprei
2010-02-01  8:46 ` [Qemu-devel] " Kevin Wolf
2010-02-01  9:06   ` Christoph Hellwig
2010-02-01  9:25     ` Alexander Graf
2010-02-01  9:27       ` Christoph Hellwig
2010-02-01 10:05         ` Alexander Graf
2010-02-01 12:32         ` Jamie Lokier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).