From f511f5b093b500474168bb0c7e95b1a48a0d5d42 Mon Sep 17 00:00:00 2001
From: Kevin Wolf <kwolf@redhat.com>
Date: Tue, 5 Nov 2013 14:09:13 +0100
Subject: [PATCH 60/87] blockdev: Don't disable COR automatically with blockdev-add
RH-Author: Kevin Wolf <kwolf@redhat.com>
Message-id: <1383660558-32096-20-git-send-email-kwolf@redhat.com>
Patchwork-id: 55398
O-Subject: [RHEL-7.0 qemu-kvm PATCH 19/24] blockdev: Don't disable COR automatically with blockdev-add
Bugzilla: 978402
RH-Acked-by: Fam Zheng <famz@redhat.com>
RH-Acked-by: Max Reitz <mreitz@redhat.com>
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
If a read-only device is configured with copy-on-read=on, the old code
only prints a warning and automatically disables copy on read. Make it
a real error for blockdev-add.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 0ebd24e0a203cf2852c310b59fbe050190dc6c8c)
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 9 +++++++--
blockdev.c | 31 +++++++++++++++++++++++++++----
2 files changed, 34 insertions(+), 6 deletions(-)
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
block.c | 9 +++++++--
blockdev.c | 31 +++++++++++++++++++++++++++----
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index c2b6930..d11661a 100644
--- a/block.c
+++ b/block.c
@@ -746,8 +746,13 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
}
assert(bs->copy_on_read == 0); /* bdrv_new() and bdrv_close() make it so */
- if (!bs->read_only && (flags & BDRV_O_COPY_ON_READ)) {
- bdrv_enable_copy_on_read(bs);
+ if (flags & BDRV_O_COPY_ON_READ) {
+ if (!bs->read_only) {
+ bdrv_enable_copy_on_read(bs);
+ } else {
+ error_setg(errp, "Can't use copy-on-read on read-only device");
+ return -EINVAL;
+ }
}
if (filename != NULL) {
diff --git a/blockdev.c b/blockdev.c
index d4b18c5..cbf01eb 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -511,10 +511,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
- if (ro && copy_on_read) {
- error_report("warning: disabling copy_on_read on read-only drive");
- }
-
QINCREF(bs_opts);
ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv, &error);
@@ -602,6 +598,18 @@ QemuOptsList qemu_legacy_drive_opts = {
.type = QEMU_OPT_STRING,
.help = "pci address (virtio only)",
},
+
+ /* Options that are passed on, but have special semantics with -drive */
+ {
+ .name = "read-only",
+ .type = QEMU_OPT_BOOL,
+ .help = "open drive file as read-only",
+ },{
+ .name = "copy-on-read",
+ .type = QEMU_OPT_BOOL,
+ .help = "copy read data from backing file into image file",
+ },
+
{ /* end of list */ }
},
};
@@ -617,6 +625,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
int cyls, heads, secs, translation;
int max_devs, bus_id, unit_id, index;
const char *devaddr;
+ bool read_only, copy_on_read;
Error *local_err = NULL;
/* Change legacy command line options into QMP ones */
@@ -688,6 +697,20 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
}
}
+ /* copy-on-read is disabled with a warning for read-only devices */
+ read_only = qemu_opt_get_bool(legacy_opts, "read-only", false);
+ copy_on_read = qemu_opt_get_bool(legacy_opts, "copy-on-read", false);
+
+ if (read_only && copy_on_read) {
+ error_report("warning: disabling copy-on-read on read-only drive");
+ copy_on_read = false;
+ }
+
+ qdict_put(bs_opts, "read-only",
+ qstring_from_str(read_only ? "on" : "off"));
+ qdict_put(bs_opts, "copy-on-read",
+ qstring_from_str(copy_on_read ? "on" :"off"));
+
/* Controller type */
value = qemu_opt_get(legacy_opts, "if");
if (value) {
--
1.7.1