Blame SOURCES/kvm-block-honor-BDRV_O_ALLOW_RDWR-when-clearing-bs-read_.patch

76daa3
From 1bd388d808de32139d2a642d68d55793a22cbc48 Mon Sep 17 00:00:00 2001
76daa3
From: Jeffrey Cody <jcody@redhat.com>
76daa3
Date: Wed, 26 Apr 2017 20:08:50 +0200
76daa3
Subject: [PATCH 04/11] block: honor BDRV_O_ALLOW_RDWR when clearing
76daa3
 bs->read_only
76daa3
76daa3
RH-Author: Jeffrey Cody <jcody@redhat.com>
76daa3
Message-id: <7b5c2f86cb3988c2365e53d47d54d469dcb5ab2f.1493236824.git.jcody@redhat.com>
76daa3
Patchwork-id: 74898
76daa3
O-Subject: [RHEV-7.4 qemu-kvm-rhev 3/8] block: honor BDRV_O_ALLOW_RDWR when clearing bs->read_only
76daa3
Bugzilla: 1189998
76daa3
RH-Acked-by: John Snow <jsnow@redhat.com>
76daa3
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
76daa3
RH-Acked-by: Max Reitz <mreitz@redhat.com>
76daa3
76daa3
The BDRV_O_ALLOW_RDWR flag allows / prohibits the changing of
76daa3
the BDS 'read_only' state, but there are a few places where it
76daa3
is ignored.  In the bdrv_set_read_only() helper, make sure to
76daa3
honor the flag.
76daa3
76daa3
Signed-off-by: Jeff Cody <jcody@redhat.com>
76daa3
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
76daa3
Reviewed-by: John Snow <jsnow@redhat.com>
76daa3
Message-id: be2e5fb2d285cbece2b6d06bed54a6f56520d251.1491597120.git.jcody@redhat.com
76daa3
(cherry picked from commit d6fcdf06d9fc7d72151cc2069dc5c1adf5c21707)
76daa3
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
---
76daa3
 block.c | 7 +++++++
76daa3
 1 file changed, 7 insertions(+)
76daa3
76daa3
diff --git a/block.c b/block.c
76daa3
index 4766b8a..b74d445 100644
76daa3
--- a/block.c
76daa3
+++ b/block.c
76daa3
@@ -201,6 +201,13 @@ int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
76daa3
         return -EINVAL;
76daa3
     }
76daa3
 
76daa3
+    /* Do not clear read_only if it is prohibited */
76daa3
+    if (!read_only && !(bs->open_flags & BDRV_O_ALLOW_RDWR)) {
76daa3
+        error_setg(errp, "Node '%s' is read only",
76daa3
+                   bdrv_get_device_or_node_name(bs));
76daa3
+        return -EPERM;
76daa3
+    }
76daa3
+
76daa3
     bs->read_only = read_only;
76daa3
     return 0;
76daa3
 }
76daa3
-- 
76daa3
1.8.3.1
76daa3