summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-10-12 11:27:41 +0200
committerKevin Wolf <kwolf@redhat.com>2018-11-05 15:09:55 +0100
commiteaa2410f1ea864609090c0a5fda9e0ce9499da79 (patch)
tree68021063e0cf17887ba5cad0e7687dd485bd8ed5 /block
parenta51b9c4862c29f427931f45ee1d39ac1663ba859 (diff)
block: Require auto-read-only for existing fallbacks
Some block drivers have traditionally changed their node to read-only mode without asking the user. This behaviour has been marked deprecated since 2.11, expecting users to provide an explicit read-only=on option. Now that we have auto-read-only=on, enable these drivers to make use of the option. This is the only use of bdrv_set_read_only(), so we can make it a bit more specific and turn it into a bdrv_apply_auto_read_only() that is more convenient for drivers to use. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/bochs.c17
-rw-r--r--block/cloop.c16
-rw-r--r--block/dmg.c16
-rw-r--r--block/rbd.c15
-rw-r--r--block/vvfat.c10
5 files changed, 22 insertions, 52 deletions
diff --git a/block/bochs.c b/block/bochs.c
index 50c630047b..22e7d44211 100644
--- a/block/bochs.c
+++ b/block/bochs.c
@@ -105,23 +105,18 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
struct bochs_header bochs;
int ret;
+ /* No write support yet */
+ ret = bdrv_apply_auto_read_only(bs, NULL, errp);
+ if (ret < 0) {
+ return ret;
+ }
+
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
false, errp);
if (!bs->file) {
return -EINVAL;
}
- if (!bdrv_is_read_only(bs)) {
- error_report("Opening bochs images without an explicit read-only=on "
- "option is deprecated. Future versions will refuse to "
- "open the image instead of automatically marking the "
- "image read-only.");
- ret = bdrv_set_read_only(bs, true, errp); /* no write support yet */
- if (ret < 0) {
- return ret;
- }
- }
-
ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs));
if (ret < 0) {
return ret;
diff --git a/block/cloop.c b/block/cloop.c
index 2be68987bd..df2b85f723 100644
--- a/block/cloop.c
+++ b/block/cloop.c
@@ -67,23 +67,17 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
uint32_t offsets_size, max_compressed_block_size = 1, i;
int ret;
+ ret = bdrv_apply_auto_read_only(bs, NULL, errp);
+ if (ret < 0) {
+ return ret;
+ }
+
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
false, errp);
if (!bs->file) {
return -EINVAL;
}
- if (!bdrv_is_read_only(bs)) {
- error_report("Opening cloop images without an explicit read-only=on "
- "option is deprecated. Future versions will refuse to "
- "open the image instead of automatically marking the "
- "image read-only.");
- ret = bdrv_set_read_only(bs, true, errp);
- if (ret < 0) {
- return ret;
- }
- }
-
/* read header */
ret = bdrv_pread(bs->file, 128, &s->block_size, 4);
if (ret < 0) {
diff --git a/block/dmg.c b/block/dmg.c
index c9b3c519c4..1d9283ba2f 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -413,23 +413,17 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
int64_t offset;
int ret;
+ ret = bdrv_apply_auto_read_only(bs, NULL, errp);
+ if (ret < 0) {
+ return ret;
+ }
+
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
false, errp);
if (!bs->file) {
return -EINVAL;
}
- if (!bdrv_is_read_only(bs)) {
- error_report("Opening dmg images without an explicit read-only=on "
- "option is deprecated. Future versions will refuse to "
- "open the image instead of automatically marking the "
- "image read-only.");
- ret = bdrv_set_read_only(bs, true, errp);
- if (ret < 0) {
- return ret;
- }
- }
-
block_module_load_one("dmg-bz2");
s->n_chunks = 0;
diff --git a/block/rbd.c b/block/rbd.c
index 1e9819a50f..8a1a9f4b6e 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -780,17 +780,10 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
/* If we are using an rbd snapshot, we must be r/o, otherwise
* leave as-is */
if (s->snap != NULL) {
- if (!bdrv_is_read_only(bs)) {
- error_report("Opening rbd snapshots without an explicit "
- "read-only=on option is deprecated. Future versions "
- "will refuse to open the image instead of "
- "automatically marking the image read-only.");
- r = bdrv_set_read_only(bs, true, &local_err);
- if (r < 0) {
- rbd_close(s->image);
- error_propagate(errp, local_err);
- goto failed_open;
- }
+ r = bdrv_apply_auto_read_only(bs, "rbd snapshots are read-only", errp);
+ if (r < 0) {
+ rbd_close(s->image);
+ goto failed_open;
}
}
diff --git a/block/vvfat.c b/block/vvfat.c
index 98ba5e2bac..e4df255d58 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1262,15 +1262,9 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
"Unable to set VVFAT to 'rw' when drive is read-only");
goto fail;
}
- } else if (!bdrv_is_read_only(bs)) {
- error_report("Opening non-rw vvfat images without an explicit "
- "read-only=on option is deprecated. Future versions "
- "will refuse to open the image instead of "
- "automatically marking the image read-only.");
- /* read only is the default for safety */
- ret = bdrv_set_read_only(bs, true, &local_err);
+ } else {
+ ret = bdrv_apply_auto_read_only(bs, NULL, errp);
if (ret < 0) {
- error_propagate(errp, local_err);
goto fail;
}
}