|
|
357786 |
From 77e6d5c8d54be29781b15bc7dbb816dd156812a0 Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Date: Mon, 18 Jun 2018 18:00:53 +0200
|
|
|
357786 |
Subject: [PATCH 47/54] block: Make bdrv_is_writable() public
|
|
|
357786 |
|
|
|
357786 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Message-id: <20180618180055.22739-2-mreitz@redhat.com>
|
|
|
357786 |
Patchwork-id: 80792
|
|
|
357786 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 1/3] block: Make bdrv_is_writable() public
|
|
|
357786 |
Bugzilla: 1588039
|
|
|
357786 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
357786 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
This is a useful function for the whole block layer, so make it public.
|
|
|
357786 |
At the same time, users outside of block.c probably do not need to make
|
|
|
357786 |
use of the reopen functionality, so rename the current function to
|
|
|
357786 |
bdrv_is_writable_after_reopen() create a new bdrv_is_writable() function
|
|
|
357786 |
that just passes NULL to it for the reopen queue.
|
|
|
357786 |
|
|
|
357786 |
Cc: qemu-stable@nongnu.org
|
|
|
357786 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Message-id: 20180606193702.7113-2-mreitz@redhat.com
|
|
|
357786 |
Reviewed-by: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Reviewed-by: Jeff Cody <jcody@redhat.com>
|
|
|
357786 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
(cherry picked from commit cc022140972f8b6ac3973c12ccf9dd6b1d2fd200)
|
|
|
357786 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
block.c | 17 ++++++++++++++---
|
|
|
357786 |
include/block/block.h | 1 +
|
|
|
357786 |
2 files changed, 15 insertions(+), 3 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/block.c b/block.c
|
|
|
357786 |
index 3c3e8fd..982d54e 100644
|
|
|
357786 |
--- a/block.c
|
|
|
357786 |
+++ b/block.c
|
|
|
357786 |
@@ -1621,13 +1621,24 @@ static int bdrv_reopen_get_flags(BlockReopenQueue *q, BlockDriverState *bs)
|
|
|
357786 |
|
|
|
357786 |
/* Returns whether the image file can be written to after the reopen queue @q
|
|
|
357786 |
* has been successfully applied, or right now if @q is NULL. */
|
|
|
357786 |
-static bool bdrv_is_writable(BlockDriverState *bs, BlockReopenQueue *q)
|
|
|
357786 |
+static bool bdrv_is_writable_after_reopen(BlockDriverState *bs,
|
|
|
357786 |
+ BlockReopenQueue *q)
|
|
|
357786 |
{
|
|
|
357786 |
int flags = bdrv_reopen_get_flags(q, bs);
|
|
|
357786 |
|
|
|
357786 |
return (flags & (BDRV_O_RDWR | BDRV_O_INACTIVE)) == BDRV_O_RDWR;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+/*
|
|
|
357786 |
+ * Return whether the BDS can be written to. This is not necessarily
|
|
|
357786 |
+ * the same as !bdrv_is_read_only(bs), as inactivated images may not
|
|
|
357786 |
+ * be written to but do not count as read-only images.
|
|
|
357786 |
+ */
|
|
|
357786 |
+bool bdrv_is_writable(BlockDriverState *bs)
|
|
|
357786 |
+{
|
|
|
357786 |
+ return bdrv_is_writable_after_reopen(bs, NULL);
|
|
|
357786 |
+}
|
|
|
357786 |
+
|
|
|
357786 |
static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs,
|
|
|
357786 |
BdrvChild *c, const BdrvChildRole *role,
|
|
|
357786 |
BlockReopenQueue *reopen_queue,
|
|
|
357786 |
@@ -1665,7 +1676,7 @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q,
|
|
|
357786 |
|
|
|
357786 |
/* Write permissions never work with read-only images */
|
|
|
357786 |
if ((cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) &&
|
|
|
357786 |
- !bdrv_is_writable(bs, q))
|
|
|
357786 |
+ !bdrv_is_writable_after_reopen(bs, q))
|
|
|
357786 |
{
|
|
|
357786 |
error_setg(errp, "Block node is read-only");
|
|
|
357786 |
return -EPERM;
|
|
|
357786 |
@@ -1957,7 +1968,7 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
|
|
|
357786 |
&perm, &shared);
|
|
|
357786 |
|
|
|
357786 |
/* Format drivers may touch metadata even if the guest doesn't write */
|
|
|
357786 |
- if (bdrv_is_writable(bs, reopen_queue)) {
|
|
|
357786 |
+ if (bdrv_is_writable_after_reopen(bs, reopen_queue)) {
|
|
|
357786 |
perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
diff --git a/include/block/block.h b/include/block/block.h
|
|
|
357786 |
index 3894edd..06cd772 100644
|
|
|
357786 |
--- a/include/block/block.h
|
|
|
357786 |
+++ b/include/block/block.h
|
|
|
357786 |
@@ -407,6 +407,7 @@ bool bdrv_is_read_only(BlockDriverState *bs);
|
|
|
357786 |
int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only,
|
|
|
357786 |
bool ignore_allow_rdw, Error **errp);
|
|
|
357786 |
int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp);
|
|
|
357786 |
+bool bdrv_is_writable(BlockDriverState *bs);
|
|
|
357786 |
bool bdrv_is_sg(BlockDriverState *bs);
|
|
|
357786 |
bool bdrv_is_inserted(BlockDriverState *bs);
|
|
|
357786 |
void bdrv_lock_medium(BlockDriverState *bs, bool locked);
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|