From 933635fed9341bfdb4813fced23c66c7d9848b25 Mon Sep 17 00:00:00 2001
From: Jeffrey Cody <jcody@redhat.com>
Date: Wed, 26 Apr 2017 20:08:52 +0200
Subject: [PATCH 06/11] block: introduce bdrv_can_set_read_only()
RH-Author: Jeffrey Cody <jcody@redhat.com>
Message-id: <332c4906d8d1ccc4efc19d57e52297a842c1486e.1493236824.git.jcody@redhat.com>
Patchwork-id: 74900
O-Subject: [RHEV-7.4 qemu-kvm-rhev 5/8] block: introduce bdrv_can_set_read_only()
Bugzilla: 1189998
RH-Acked-by: John Snow <jsnow@redhat.com>
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
RH-Acked-by: Max Reitz <mreitz@redhat.com>
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
(cherry picked from commit 45803a039670cbee914dcb54cf3952f9b2d64d1f)
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
block.c | 14 +++++++++++++-
include/block/block.h | 1 +
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/block.c b/block.c
index bf09026..84f12f7 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;
}
diff --git a/include/block/block.h b/include/block/block.h
index 3525590..56b27fb 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -434,6 +434,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
int64_t sector_num, int nb_sectors, int *pnum);
bool bdrv_is_read_only(BlockDriverState *bs);
+int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp);
int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp);
bool bdrv_is_sg(BlockDriverState *bs);
bool bdrv_is_inserted(BlockDriverState *bs);
--
1.8.3.1