Skip to contentSkip to conversation

block: saner flags filtering in bdrv_open2

PATCH Applied Christoph Hellwig 2 participants 3 messages Jan 28, 2010 – Feb 10, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: saner flags filtering in bdrv_open2

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.

block.c +14 -7
Index: qemu/block.c
===================================================================
@@ -451,13 +451,20 @@ int bdrv_open2(BlockDriverState *bs, con
         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);
#1 lore raw

ping?

Quoted 31 lines · Christoph Hellwig

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.

Index: qemu/block.c
===================================================================

block.c +7 -7
@@ -451,13 +451,20 @@ int bdrv_open2(BlockDriverState *bs, con
         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);
+

block.c int bdrv_open2(BlockDriverState *bs, con · line 470

Quoted 10 lines
block.c +7 -0
+    /*
+     * 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);

---end quoted text---

#2 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

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.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 36 lines

Index: qemu/block.c
===================================================================

block.c +14 -7
@@ -451,13 +451,20 @@ int bdrv_open2(BlockDriverState *bs, con
          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);