All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/2] block: untangle open flag manipulation in bdrv_open2
Date: Mon, 11 Jan 2010 18:52:09 +0100	[thread overview]
Message-ID: <20100111175209.GB7571@lst.de> (raw)

Untangle the open flag manipulation in bdrv_open2 and document why we
are clearing the various flags in the different flag combinations.


Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: qemu/block.c
===================================================================
--- qemu.orig/block.c	2010-01-11 17:52:54.273003789 +0100
+++ qemu/block.c	2010-01-11 18:19:22.485006278 +0100
@@ -356,7 +356,7 @@ int bdrv_open(BlockDriverState *bs, cons
 int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
                BlockDriver *drv)
 {
-    int ret, open_flags, try_rw;
+    int ret, open_flags;
     char tmp_filename[PATH_MAX];
     char backing_filename[PATH_MAX];
 
@@ -450,19 +450,39 @@ int bdrv_open2(BlockDriverState *bs, con
     if (flags & (BDRV_O_CACHE_WB|BDRV_O_NOCACHE))
         bs->enable_write_cache = 1;
 
-    /* Note: for compatibility, we open disk image files as RDWR, and
-       RDONLY as fallback */
-    try_rw = !bs->read_only || bs->is_temporary;
-    if (!(flags & BDRV_O_FILE))
-        open_flags = (try_rw ? BDRV_O_RDWR : 0) |
-            (flags & (BDRV_O_CACHE_MASK|BDRV_O_NATIVE_AIO));
-    else
-        open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
+    /*
+     * Always clear these flags as they are not destined for the drivers.
+     */
+    open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
+
+    if (!(flags & BDRV_O_FILE)) {
+        /*
+         * For historical reasons we always try to open drive images as
+         * read-write first and only fall back to read-only later.
+         *
+         * This can be overriden using readonly suboption for the
+         * drive option.
+         */
+        if (bs->read_only && !bs->is_temporary) {
+            open_flags &= ~BDRV_O_RDWR;
+        } else {
+            open_flags |= BDRV_O_RDWR;
+        }
 
-    ret = drv->bdrv_open(bs, filename, open_flags);
-    if ((ret == -EACCES || ret == -EPERM) && !(flags & BDRV_O_FILE)) {
-        ret = drv->bdrv_open(bs, filename, open_flags & ~BDRV_O_RDWR);
-        bs->read_only = 1;
+        /*
+         * Currently BDRV_O_CREAT is not supported by any image format,
+         * but I'm not sure that's reason enough to always clear it for
+         * the !BDRV_O_FILE case..
+         */
+        open_flags &= ~(BDRV_O_CREAT);
+
+        ret = drv->bdrv_open(bs, filename, open_flags);
+        if (ret == -EACCES || ret == -EPERM) {
+            ret = drv->bdrv_open(bs, filename, open_flags & ~BDRV_O_RDWR);
+            bs->read_only = 1;
+        }
+    } else {
+        ret = drv->bdrv_open(bs, filename, open_flags);
     }
 
     if (ret < 0) {

             reply	other threads:[~2010-01-11 17:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-11 17:52 Christoph Hellwig [this message]
2010-01-12 17:32 ` [Qemu-devel] [PATCH 2/2] block: untangle open flag manipulation in bdrv_open2 Kevin Wolf
2010-01-12 17:37   ` Christoph Hellwig
2010-01-19 21:00 ` [Qemu-devel] PATCH 3/2] block: kill BDRV_O_CREAT Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100111175209.GB7571@lst.de \
    --to=hch@lst.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.