]> git.proxmox.com Git - qemu.git/commitdiff
block: saner flags filtering in bdrv_open2
authorChristoph Hellwig <hch@lst.de>
Thu, 28 Jan 2010 14:19:12 +0000 (15:19 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Wed, 10 Feb 2010 17:57:03 +0000 (11:57 -0600)
Clean up the current mess about figuring out which flags to pass to the
driver.  BDRV_O_FILE, BDRV_O_SNAPSHOT and BDRV_O_NO_BACKING are flags
only used by the block layer internally so filter them out directly.
Previously BDRV_O_NO_BACKING could accidentally be passed to the drivers,
but wasn't ever used.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
block.c

diff --git a/block.c b/block.c
index baf646c308b060c00034d711cb8a0edd62c8e3eb..bbaaa1b4a1602f6e5f228ed8ccb6d83fe08f3734 100644 (file)
--- a/block.c
+++ b/block.c
@@ -451,13 +451,20 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
         bs->enable_write_cache = 1;
 
     bs->read_only = (flags & BDRV_O_RDWR) == 0;
-    if (!(flags & BDRV_O_FILE)) {
-        open_flags = (flags & (BDRV_O_RDWR | BDRV_O_CACHE_MASK|BDRV_O_NATIVE_AIO));
-        if (bs->is_temporary) { /* snapshot should be writeable */
-            open_flags |= BDRV_O_RDWR;
-        }
-    } else {
-        open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
+
+    /*
+     * Clear flags that are internal to the block layer before opening the
+     * image.
+     */
+    open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
+
+    /*
+     * Snapshots should be writeable.
+     *
+     * XXX(hch): and what is the point of a snapshot during a read-only open?
+     */
+    if (!(flags & BDRV_O_FILE) && bs->is_temporary) {
+        open_flags |= BDRV_O_RDWR;
     }
 
     ret = drv->bdrv_open(bs, filename, open_flags);