@@ -654,6 +654,18 @@ void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm)
*shared_perm = blk->shared_perm;
}
+int blk_request_perm(BlockBackend *blk, uint64_t perm, Error **errp)
+{
+ uint64_t blk_perm, shared_perm;
+
+ blk_get_perm(blk, &blk_perm, &shared_perm);
+ if ((blk_perm & perm) == perm) {
+ return 0;
+ }
+ blk_perm |= perm;
+ return blk_set_perm(blk, blk_perm, shared_perm, errp);
+}
+
static int blk_do_attach_dev(BlockBackend *blk, void *dev)
{
if (blk->dev) {
@@ -116,6 +116,7 @@ bool bdrv_is_root_node(BlockDriverState *bs);
int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm,
Error **errp);
void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm);
+int blk_request_perm(BlockBackend *blk, uint64_t perm, Error **errp);
void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow);
void blk_iostatus_enable(BlockBackend *blk);
This function tries to request, if not granted yet, for the given permissions. Signed-off-by: Fam Zheng <famz@redhat.com> --- block/block-backend.c | 12 ++++++++++++ include/sysemu/block-backend.h | 1 + 2 files changed, 13 insertions(+)