From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, benoit.canet@irqsave.net, armbru@redhat.com,
mreitz@redhat.com, stefanha@redhat.com,
xiawenc@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v2 16/17] blockdev: Don't disable COR automatically with blockdev-add
Date: Tue, 1 Oct 2013 15:20:18 +0200 [thread overview]
Message-ID: <1380633619-12213-17-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1380633619-12213-1-git-send-email-kwolf@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>
---
block.c | 9 +++++++--
blockdev.c | 31 +++++++++++++++++++++++++++----
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index 93e113a..dc63f02 100644
--- a/block.c
+++ b/block.c
@@ -774,8 +774,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 bb6a1d5..4f015af 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -514,10 +514,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);
@@ -605,6 +601,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 */ }
},
};
@@ -620,6 +628,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 */
@@ -702,6 +711,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.8.1.4
next prev parent reply other threads:[~2013-10-01 13:21 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-01 13:20 [Qemu-devel] [PATCH v2 00/17] blockdev-add QMP command Kevin Wolf
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 01/17] qapi-types/visit.py: Pass whole expr dict for structs Kevin Wolf
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 02/17] qapi-types/visit.py: Inheritance " Kevin Wolf
2013-10-01 15:21 ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 03/17] blockdev: Introduce DriveInfo.enable_auto_del Kevin Wolf
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 04/17] blockdev: 'blockdev-add' QMP command Kevin Wolf
2013-10-01 14:00 ` Benoît Canet
2013-10-01 15:41 ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 05/17] blockdev: Separate ID generation from DriveInfo creation Kevin Wolf
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 06/17] blockdev: Pass QDict to blockdev_init() Kevin Wolf
2013-10-01 15:53 ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 07/17] blockdev: Move parsing of 'media' option to drive_init Kevin Wolf
2013-10-01 15:57 ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 08/17] blockdev: Move parsing of 'if' " Kevin Wolf
2013-10-01 14:44 ` Benoît Canet
2013-10-01 16:01 ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 09/17] blockdev: Moving parsing of geometry options " Kevin Wolf
2013-10-01 16:09 ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 10/17] blockdev: Move parsing of 'boot' option " Kevin Wolf
2013-10-01 16:19 ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 11/17] blockdev: Move bus/unit/index processing " Kevin Wolf
2013-10-01 16:25 ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 12/17] blockdev: Move virtio-blk device creation " Kevin Wolf
2013-10-01 16:34 ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 13/17] blockdev: Remove IF_* check for read-only blockdev_init Kevin Wolf
2013-10-01 16:51 ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 14/17] qemu-iotests: Check autodel behaviour for device_del Kevin Wolf
2013-10-01 17:06 ` Eric Blake
2013-10-08 9:44 ` Kevin Wolf
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 15/17] blockdev: Remove 'media' parameter from blockdev_init() Kevin Wolf
2013-10-01 17:07 ` Eric Blake
2013-10-01 13:20 ` Kevin Wolf [this message]
2013-10-01 17:09 ` [Qemu-devel] [PATCH v2 16/17] blockdev: Don't disable COR automatically with blockdev-add Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 17/17] blockdev: blockdev_init() error conversion Kevin Wolf
2013-10-01 17:11 ` Eric Blake
2013-10-01 15:41 ` [Qemu-devel] [PATCH v2 00/17] blockdev-add QMP command Eric Blake
2013-10-01 15:50 ` Kevin Wolf
2013-10-01 15:54 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1380633619-12213-17-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=benoit.canet@irqsave.net \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=xiawenc@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).