aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorJeff Cody <jcody@redhat.com>2017-04-07 16:55:29 -0400
committerJeff Cody <jcody@redhat.com>2017-04-24 15:09:33 -0400
commit45803a039670cbee914dcb54cf3952f9b2d64d1f (patch)
treee7b00a02d73fc7aca6093f17ab2afa834b197ace /block.c
parent93ed524e3de732f70b3b042e3c56bc4ed719498d (diff)
downloadqemu-45803a039670cbee914dcb54cf3952f9b2d64d1f.zip
qemu-45803a039670cbee914dcb54cf3952f9b2d64d1f.tar.gz
qemu-45803a039670cbee914dcb54cf3952f9b2d64d1f.tar.bz2
block: introduce bdrv_can_set_read_only()
Introduce check function for setting read_only flags. Will return < 0 on error, with appropriate Error value set. Does not alter any flags. Signed-off-by: Jeff Cody <jcody@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Message-id: e2bba34ac3bc76a0c42adc390413f358ae0566e8.1491597120.git.jcody@redhat.com
Diffstat (limited to 'block.c')
-rw-r--r--block.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/block.c b/block.c
index 123c982..1ac05c1 100644
--- a/block.c
+++ b/block.c
@@ -197,7 +197,7 @@ bool bdrv_is_read_only(BlockDriverState *bs)
return bs->read_only;
}
-int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
+int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
{
/* Do not set read_only if copy_on_read is enabled */
if (bs->copy_on_read && read_only) {
@@ -213,6 +213,18 @@ int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
return -EPERM;
}
+ return 0;
+}
+
+int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
+{
+ int ret = 0;
+
+ ret = bdrv_can_set_read_only(bs, read_only, errp);
+ if (ret < 0) {
+ return ret;
+ }
+
bs->read_only = read_only;
return 0;
}