From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2jWy-0001Xc-3J for qemu-devel@nongnu.org; Mon, 24 Apr 2017 15:20:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2jWx-0002gk-4y for qemu-devel@nongnu.org; Mon, 24 Apr 2017 15:20:16 -0400 From: Jeff Cody Date: Mon, 24 Apr 2017 15:19:56 -0400 Message-Id: <20170424192002.18622-7-jcody@redhat.com> In-Reply-To: <20170424192002.18622-1-jcody@redhat.com> References: <20170424192002.18622-1-jcody@redhat.com> Subject: [Qemu-devel] [PULL v2 06/12] block: honor BDRV_O_ALLOW_RDWR when clearing bs->read_only List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org The BDRV_O_ALLOW_RDWR flag allows / prohibits the changing of the BDS 'read_only' state, but there are a few places where it is ignored. In the bdrv_set_read_only() helper, make sure to honor the flag. Signed-off-by: Jeff Cody Reviewed-by: Stefan Hajnoczi Reviewed-by: John Snow Message-id: be2e5fb2d285cbece2b6d06bed54a6f56520d251.1491597120.git.jcody@redhat.com --- block.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block.c b/block.c index 67ae35a..4752fee 100644 --- a/block.c +++ b/block.c @@ -201,6 +201,13 @@ int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) return -EINVAL; } + /* Do not clear read_only if it is prohibited */ + if (!read_only && !(bs->open_flags & BDRV_O_ALLOW_RDWR)) { + error_setg(errp, "Node '%s' is read only", + bdrv_get_device_or_node_name(bs)); + return -EPERM; + } + bs->read_only = read_only; return 0; } -- 2.9.3