|
|
26ba25 |
From 60065cb41272144762ceb38e9bcd1a203c29c064 Mon Sep 17 00:00:00 2001
|
|
|
26ba25 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
26ba25 |
Date: Thu, 10 Jan 2019 12:44:34 +0000
|
|
|
26ba25 |
Subject: [PATCH 04/14] block: Require auto-read-only for existing fallbacks
|
|
|
26ba25 |
|
|
|
26ba25 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
26ba25 |
Message-id: <20190110124442.30132-5-kwolf@redhat.com>
|
|
|
26ba25 |
Patchwork-id: 83954
|
|
|
26ba25 |
O-Subject: [RHEL-8.0 qemu-kvm PATCH 04/12] block: Require auto-read-only for existing fallbacks
|
|
|
26ba25 |
Bugzilla: 1644996
|
|
|
26ba25 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
26ba25 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
26ba25 |
RH-Acked-by: Eric Blake <eblake@redhat.com>
|
|
|
26ba25 |
|
|
|
26ba25 |
Some block drivers have traditionally changed their node to read-only
|
|
|
26ba25 |
mode without asking the user. This behaviour has been marked deprecated
|
|
|
26ba25 |
since 2.11, expecting users to provide an explicit read-only=on option.
|
|
|
26ba25 |
|
|
|
26ba25 |
Now that we have auto-read-only=on, enable these drivers to make use of
|
|
|
26ba25 |
the option.
|
|
|
26ba25 |
|
|
|
26ba25 |
This is the only use of bdrv_set_read_only(), so we can make it a bit
|
|
|
26ba25 |
more specific and turn it into a bdrv_apply_auto_read_only() that is
|
|
|
26ba25 |
more convenient for drivers to use.
|
|
|
26ba25 |
|
|
|
26ba25 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
26ba25 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
26ba25 |
(cherry picked from commit eaa2410f1ea864609090c0a5fda9e0ce9499da79)
|
|
|
26ba25 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
26ba25 |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
26ba25 |
---
|
|
|
26ba25 |
block.c | 42 +++++++++++++++++++++++++++---------------
|
|
|
26ba25 |
block/bochs.c | 17 ++++++-----------
|
|
|
26ba25 |
block/cloop.c | 16 +++++-----------
|
|
|
26ba25 |
block/dmg.c | 16 +++++-----------
|
|
|
26ba25 |
block/rbd.c | 15 ++++-----------
|
|
|
26ba25 |
block/vvfat.c | 10 ++--------
|
|
|
26ba25 |
include/block/block.h | 3 ++-
|
|
|
26ba25 |
7 files changed, 51 insertions(+), 68 deletions(-)
|
|
|
26ba25 |
|
|
|
26ba25 |
diff --git a/block.c b/block.c
|
|
|
26ba25 |
index f357975..268debe 100644
|
|
|
26ba25 |
--- a/block.c
|
|
|
26ba25 |
+++ b/block.c
|
|
|
26ba25 |
@@ -266,29 +266,41 @@ int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only,
|
|
|
26ba25 |
return 0;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
-/* TODO Remove (deprecated since 2.11)
|
|
|
26ba25 |
- * Block drivers are not supposed to automatically change bs->read_only.
|
|
|
26ba25 |
- * Instead, they should just check whether they can provide what the user
|
|
|
26ba25 |
- * explicitly requested and error out if read-write is requested, but they can
|
|
|
26ba25 |
- * only provide read-only access. */
|
|
|
26ba25 |
-int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
|
|
|
26ba25 |
+/*
|
|
|
26ba25 |
+ * Called by a driver that can only provide a read-only image.
|
|
|
26ba25 |
+ *
|
|
|
26ba25 |
+ * Returns 0 if the node is already read-only or it could switch the node to
|
|
|
26ba25 |
+ * read-only because BDRV_O_AUTO_RDONLY is set.
|
|
|
26ba25 |
+ *
|
|
|
26ba25 |
+ * Returns -EACCES if the node is read-write and BDRV_O_AUTO_RDONLY is not set
|
|
|
26ba25 |
+ * or bdrv_can_set_read_only() forbids making the node read-only. If @errmsg
|
|
|
26ba25 |
+ * is not NULL, it is used as the error message for the Error object.
|
|
|
26ba25 |
+ */
|
|
|
26ba25 |
+int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg,
|
|
|
26ba25 |
+ Error **errp)
|
|
|
26ba25 |
{
|
|
|
26ba25 |
int ret = 0;
|
|
|
26ba25 |
|
|
|
26ba25 |
- ret = bdrv_can_set_read_only(bs, read_only, false, errp);
|
|
|
26ba25 |
- if (ret < 0) {
|
|
|
26ba25 |
- return ret;
|
|
|
26ba25 |
+ if (!(bs->open_flags & BDRV_O_RDWR)) {
|
|
|
26ba25 |
+ return 0;
|
|
|
26ba25 |
+ }
|
|
|
26ba25 |
+ if (!(bs->open_flags & BDRV_O_AUTO_RDONLY)) {
|
|
|
26ba25 |
+ goto fail;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
- bs->read_only = read_only;
|
|
|
26ba25 |
-
|
|
|
26ba25 |
- if (read_only) {
|
|
|
26ba25 |
- bs->open_flags &= ~BDRV_O_RDWR;
|
|
|
26ba25 |
- } else {
|
|
|
26ba25 |
- bs->open_flags |= BDRV_O_RDWR;
|
|
|
26ba25 |
+ ret = bdrv_can_set_read_only(bs, true, false, NULL);
|
|
|
26ba25 |
+ if (ret < 0) {
|
|
|
26ba25 |
+ goto fail;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
+ bs->read_only = true;
|
|
|
26ba25 |
+ bs->open_flags &= ~BDRV_O_RDWR;
|
|
|
26ba25 |
+
|
|
|
26ba25 |
return 0;
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+fail:
|
|
|
26ba25 |
+ error_setg(errp, "%s", errmsg ?: "Image is read-only");
|
|
|
26ba25 |
+ return -EACCES;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
void bdrv_get_full_backing_filename_from_filename(const char *backed,
|
|
|
26ba25 |
diff --git a/block/bochs.c b/block/bochs.c
|
|
|
26ba25 |
index 50c6300..22e7d44 100644
|
|
|
26ba25 |
--- a/block/bochs.c
|
|
|
26ba25 |
+++ b/block/bochs.c
|
|
|
26ba25 |
@@ -105,23 +105,18 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
26ba25 |
struct bochs_header bochs;
|
|
|
26ba25 |
int ret;
|
|
|
26ba25 |
|
|
|
26ba25 |
+ /* No write support yet */
|
|
|
26ba25 |
+ ret = bdrv_apply_auto_read_only(bs, NULL, errp);
|
|
|
26ba25 |
+ if (ret < 0) {
|
|
|
26ba25 |
+ return ret;
|
|
|
26ba25 |
+ }
|
|
|
26ba25 |
+
|
|
|
26ba25 |
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
|
|
26ba25 |
false, errp);
|
|
|
26ba25 |
if (!bs->file) {
|
|
|
26ba25 |
return -EINVAL;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
- if (!bdrv_is_read_only(bs)) {
|
|
|
26ba25 |
- error_report("Opening bochs images without an explicit read-only=on "
|
|
|
26ba25 |
- "option is deprecated. Future versions will refuse to "
|
|
|
26ba25 |
- "open the image instead of automatically marking the "
|
|
|
26ba25 |
- "image read-only.");
|
|
|
26ba25 |
- ret = bdrv_set_read_only(bs, true, errp); /* no write support yet */
|
|
|
26ba25 |
- if (ret < 0) {
|
|
|
26ba25 |
- return ret;
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
-
|
|
|
26ba25 |
ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs));
|
|
|
26ba25 |
if (ret < 0) {
|
|
|
26ba25 |
return ret;
|
|
|
26ba25 |
diff --git a/block/cloop.c b/block/cloop.c
|
|
|
26ba25 |
index 2be6898..df2b85f 100644
|
|
|
26ba25 |
--- a/block/cloop.c
|
|
|
26ba25 |
+++ b/block/cloop.c
|
|
|
26ba25 |
@@ -67,23 +67,17 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
26ba25 |
uint32_t offsets_size, max_compressed_block_size = 1, i;
|
|
|
26ba25 |
int ret;
|
|
|
26ba25 |
|
|
|
26ba25 |
+ ret = bdrv_apply_auto_read_only(bs, NULL, errp);
|
|
|
26ba25 |
+ if (ret < 0) {
|
|
|
26ba25 |
+ return ret;
|
|
|
26ba25 |
+ }
|
|
|
26ba25 |
+
|
|
|
26ba25 |
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
|
|
26ba25 |
false, errp);
|
|
|
26ba25 |
if (!bs->file) {
|
|
|
26ba25 |
return -EINVAL;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
- if (!bdrv_is_read_only(bs)) {
|
|
|
26ba25 |
- error_report("Opening cloop images without an explicit read-only=on "
|
|
|
26ba25 |
- "option is deprecated. Future versions will refuse to "
|
|
|
26ba25 |
- "open the image instead of automatically marking the "
|
|
|
26ba25 |
- "image read-only.");
|
|
|
26ba25 |
- ret = bdrv_set_read_only(bs, true, errp);
|
|
|
26ba25 |
- if (ret < 0) {
|
|
|
26ba25 |
- return ret;
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
-
|
|
|
26ba25 |
/* read header */
|
|
|
26ba25 |
ret = bdrv_pread(bs->file, 128, &s->block_size, 4);
|
|
|
26ba25 |
if (ret < 0) {
|
|
|
26ba25 |
diff --git a/block/dmg.c b/block/dmg.c
|
|
|
26ba25 |
index c9b3c51..1d9283b 100644
|
|
|
26ba25 |
--- a/block/dmg.c
|
|
|
26ba25 |
+++ b/block/dmg.c
|
|
|
26ba25 |
@@ -413,23 +413,17 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
26ba25 |
int64_t offset;
|
|
|
26ba25 |
int ret;
|
|
|
26ba25 |
|
|
|
26ba25 |
+ ret = bdrv_apply_auto_read_only(bs, NULL, errp);
|
|
|
26ba25 |
+ if (ret < 0) {
|
|
|
26ba25 |
+ return ret;
|
|
|
26ba25 |
+ }
|
|
|
26ba25 |
+
|
|
|
26ba25 |
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
|
|
26ba25 |
false, errp);
|
|
|
26ba25 |
if (!bs->file) {
|
|
|
26ba25 |
return -EINVAL;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
- if (!bdrv_is_read_only(bs)) {
|
|
|
26ba25 |
- error_report("Opening dmg images without an explicit read-only=on "
|
|
|
26ba25 |
- "option is deprecated. Future versions will refuse to "
|
|
|
26ba25 |
- "open the image instead of automatically marking the "
|
|
|
26ba25 |
- "image read-only.");
|
|
|
26ba25 |
- ret = bdrv_set_read_only(bs, true, errp);
|
|
|
26ba25 |
- if (ret < 0) {
|
|
|
26ba25 |
- return ret;
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
-
|
|
|
26ba25 |
block_module_load_one("dmg-bz2");
|
|
|
26ba25 |
|
|
|
26ba25 |
s->n_chunks = 0;
|
|
|
26ba25 |
diff --git a/block/rbd.c b/block/rbd.c
|
|
|
26ba25 |
index dc369d0..8d74a29 100644
|
|
|
26ba25 |
--- a/block/rbd.c
|
|
|
26ba25 |
+++ b/block/rbd.c
|
|
|
26ba25 |
@@ -773,17 +773,10 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
26ba25 |
/* If we are using an rbd snapshot, we must be r/o, otherwise
|
|
|
26ba25 |
* leave as-is */
|
|
|
26ba25 |
if (s->snap != NULL) {
|
|
|
26ba25 |
- if (!bdrv_is_read_only(bs)) {
|
|
|
26ba25 |
- error_report("Opening rbd snapshots without an explicit "
|
|
|
26ba25 |
- "read-only=on option is deprecated. Future versions "
|
|
|
26ba25 |
- "will refuse to open the image instead of "
|
|
|
26ba25 |
- "automatically marking the image read-only.");
|
|
|
26ba25 |
- r = bdrv_set_read_only(bs, true, &local_err);
|
|
|
26ba25 |
- if (r < 0) {
|
|
|
26ba25 |
- rbd_close(s->image);
|
|
|
26ba25 |
- error_propagate(errp, local_err);
|
|
|
26ba25 |
- goto failed_open;
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
+ r = bdrv_apply_auto_read_only(bs, "rbd snapshots are read-only", errp);
|
|
|
26ba25 |
+ if (r < 0) {
|
|
|
26ba25 |
+ rbd_close(s->image);
|
|
|
26ba25 |
+ goto failed_open;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
diff --git a/block/vvfat.c b/block/vvfat.c
|
|
|
26ba25 |
index 3efce9e..a5a3fb9 100644
|
|
|
26ba25 |
--- a/block/vvfat.c
|
|
|
26ba25 |
+++ b/block/vvfat.c
|
|
|
26ba25 |
@@ -1262,15 +1262,9 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
26ba25 |
"Unable to set VVFAT to 'rw' when drive is read-only");
|
|
|
26ba25 |
goto fail;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
- } else if (!bdrv_is_read_only(bs)) {
|
|
|
26ba25 |
- error_report("Opening non-rw vvfat images without an explicit "
|
|
|
26ba25 |
- "read-only=on option is deprecated. Future versions "
|
|
|
26ba25 |
- "will refuse to open the image instead of "
|
|
|
26ba25 |
- "automatically marking the image read-only.");
|
|
|
26ba25 |
- /* read only is the default for safety */
|
|
|
26ba25 |
- ret = bdrv_set_read_only(bs, true, &local_err);
|
|
|
26ba25 |
+ } else {
|
|
|
26ba25 |
+ ret = bdrv_apply_auto_read_only(bs, NULL, errp);
|
|
|
26ba25 |
if (ret < 0) {
|
|
|
26ba25 |
- error_propagate(errp, local_err);
|
|
|
26ba25 |
goto fail;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
}
|
|
|
26ba25 |
diff --git a/include/block/block.h b/include/block/block.h
|
|
|
26ba25 |
index 6ee8b2a..36a702c 100644
|
|
|
26ba25 |
--- a/include/block/block.h
|
|
|
26ba25 |
+++ b/include/block/block.h
|
|
|
26ba25 |
@@ -433,7 +433,8 @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
|
|
|
26ba25 |
bool bdrv_is_read_only(BlockDriverState *bs);
|
|
|
26ba25 |
int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only,
|
|
|
26ba25 |
bool ignore_allow_rdw, Error **errp);
|
|
|
26ba25 |
-int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp);
|
|
|
26ba25 |
+int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg,
|
|
|
26ba25 |
+ Error **errp);
|
|
|
26ba25 |
bool bdrv_is_writable(BlockDriverState *bs);
|
|
|
26ba25 |
bool bdrv_is_sg(BlockDriverState *bs);
|
|
|
26ba25 |
bool bdrv_is_inserted(BlockDriverState *bs);
|
|
|
26ba25 |
--
|
|
|
26ba25 |
1.8.3.1
|
|
|
26ba25 |
|