From: Denis Plotnikov <dplotnikov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: armbru@redhat.com, kwolf@redhat.com, eblake@redhat.com,
famz@redhat.com, mreitz@redhat.com, stefanha@redhat.com,
jcody@redhat.com, qemu-devel@nongnu.org, den@virtuozzo.com,
rkagan@virtuozzo.com
Subject: [Qemu-devel] [PATCH v0 2/2] qmp: add block-set-copy-on-read command
Date: Wed, 13 Jun 2018 18:47:11 +0300 [thread overview]
Message-ID: <20180613154711.12977-3-dplotnikov@virtuozzo.com> (raw)
In-Reply-To: <20180613154711.12977-1-dplotnikov@virtuozzo.com>
The command enables/disables copy-on-read mode for VM's disk while
VM is running.
This is needed when using external disk readers to shape access pattern
to the disk backend.
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
---
blockdev.c | 38 ++++++++++++++++++++++++++++++++++++++
qapi/block-core.json | 20 ++++++++++++++++++++
2 files changed, 58 insertions(+)
diff --git a/blockdev.c b/blockdev.c
index 4862323012..4a297dabef 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -4276,6 +4276,44 @@ out:
aio_context_release(aio_context);
}
+void qmp_block_set_copy_on_read(const char *device, bool enable, Error **errp)
+{
+ Error *local_err = NULL;
+ AioContext *aio_context;
+ BlockDriverState *bs = bdrv_lookup_bs(device, device, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ aio_context = bdrv_get_aio_context(bs);
+ aio_context_acquire(aio_context);
+
+ if (enable) {
+ if (bs->open_flags & BDRV_O_COPY_ON_READ) {
+ error_setg(errp, "Can't enable copy-on-read for the device. "
+ "Copy-on-read is already enabled.");
+ } else {
+ if (bdrv_enable_copy_on_read(bs)) {
+ bs->open_flags |= BDRV_O_COPY_ON_READ;
+ } else {
+ error_setg(errp, "Can't enable copy-on-read. "
+ "The device is read-only.");
+ }
+ }
+ } else {
+ if (bs->open_flags & BDRV_O_COPY_ON_READ) {
+ bs->open_flags &= ~BDRV_O_COPY_ON_READ;
+ bdrv_disable_copy_on_read(bs);
+ } else {
+ error_setg(errp, "Can't disable copy-on-read for the device. "
+ "Copy-on-read is already disabled.");
+ }
+ }
+
+ aio_context_release(aio_context);
+}
+
static BdrvChild *bdrv_find_child(BlockDriverState *parent_bs,
const char *child_name)
{
diff --git a/qapi/block-core.json b/qapi/block-core.json
index fff23fc82b..7369a13009 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -4701,6 +4701,26 @@
{ 'command': 'block-set-write-threshold',
'data': { 'node-name': 'str', 'write-threshold': 'uint64' } }
+##
+# @block-set-copy-on-read:
+#
+# Enables and disables the copy-on-read property of a block device.
+#
+# @device: device or graph node name on which copy-on-read must be set.
+#
+# Since: 2.12
+#
+# Example:
+#
+# -> { "execute": "block-set-copy-on-read",
+# "arguments": { "device": "scsi0-0-0-0",
+# "enable": true } }
+# <- { "return": {} }
+#
+##
+{ 'command': 'block-set-copy-on-read',
+ 'data': { 'device': 'str', 'enable': 'bool' } }
+
##
# @x-blockdev-change:
#
--
2.17.0
next prev parent reply other threads:[~2018-06-13 15:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-13 15:47 [Qemu-devel] [PATCH v0 0/2] enable/disable copy-on-read via qmp Denis Plotnikov
2018-06-13 15:47 ` [Qemu-devel] [PATCH v0 1/2] block: check for read-only on copy-on-read setting Denis Plotnikov
2018-06-13 15:47 ` Denis Plotnikov [this message]
2018-06-13 16:02 ` [Qemu-devel] [PATCH v0 2/2] qmp: add block-set-copy-on-read command Eric Blake
2018-06-13 16:41 ` Max Reitz
2018-06-14 9:00 ` Kevin Wolf
2018-06-14 9:03 ` Alberto Garcia
2018-06-14 9:19 ` Kevin Wolf
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=20180613154711.12977-3-dplotnikov@virtuozzo.com \
--to=dplotnikov@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=den@virtuozzo.com \
--cc=eblake@redhat.com \
--cc=famz@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rkagan@virtuozzo.com \
--cc=stefanha@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.