Blame 0222-block-set-bs-read_only-before-.bdrv_open.patch

cd9d16
From b461a24186f05d7adec265bd34f348f7b8f9569b Mon Sep 17 00:00:00 2001
cd9d16
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
cd9d16
Date: Thu, 27 Oct 2011 10:54:27 +0100
cd9d16
Subject: [PATCH] block: set bs->read_only before .bdrv_open()
cd9d16
MIME-Version: 1.0
cd9d16
Content-Type: text/plain; charset=UTF-8
cd9d16
Content-Transfer-Encoding: 8bit
cd9d16
cd9d16
Several block drivers set bs->read_only in .bdrv_open() but
cd9d16
block.c:bdrv_open_common() clobbers its value.  Additionally, QED uses
cd9d16
bdrv_is_read_only() in .bdrv_open() to decide whether to perform
cd9d16
consistency checks.
cd9d16
cd9d16
The correct ordering is to initialize bs->read_only from the open flags
cd9d16
before calling .bdrv_open().  This way block drivers can override it if
cd9d16
necessary and can use bdrv_is_read_only() in .bdrv_open().
cd9d16
cd9d16
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
cd9d16
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
cd9d16
(cherry picked from commit e7c637967e6aad195b5f30cfd995913c9e0b4666)
cd9d16
cd9d16
Signed-off-by: Bruce Rogers <brogers@suse.com>
cd9d16
Signed-off-by: Andreas Färber <afaerber@suse.de>
cd9d16
---
cd9d16
 block.c | 4 ++--
cd9d16
 1 file changed, 2 insertions(+), 2 deletions(-)
cd9d16
cd9d16
diff --git a/block.c b/block.c
cd9d16
index 4ebb18b..8d77746 100644
cd9d16
--- a/block.c
cd9d16
+++ b/block.c
cd9d16
@@ -455,6 +455,8 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
cd9d16
         open_flags |= BDRV_O_RDWR;
cd9d16
     }
cd9d16
 
cd9d16
+    bs->keep_read_only = bs->read_only = !(open_flags & BDRV_O_RDWR);
cd9d16
+
cd9d16
     /* Open the image, either directly or using a protocol */
cd9d16
     if (drv->bdrv_file_open) {
cd9d16
         ret = drv->bdrv_file_open(bs, filename, open_flags);
cd9d16
@@ -469,8 +471,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
cd9d16
         goto free_and_fail;
cd9d16
     }
cd9d16
 
cd9d16
-    bs->keep_read_only = bs->read_only = !(open_flags & BDRV_O_RDWR);
cd9d16
-
cd9d16
     ret = refresh_total_sectors(bs, bs->total_sectors);
cd9d16
     if (ret < 0) {
cd9d16
         goto free_and_fail;
cd9d16
-- 
cd9d16
1.7.11.2
cd9d16