qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH v6 08/16] qmp: add block_job_set_speed command
Date: Wed, 18 Jan 2012 14:40:47 +0000	[thread overview]
Message-ID: <1326897655-2799-9-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1326897655-2799-1-git-send-email-stefanha@linux.vnet.ibm.com>

Add block_job_set_speed, which sets the maximum speed for a background
block operation.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 blockdev.c       |   25 +++++++++++++++++++++++++
 hmp-commands.hx  |   14 ++++++++++++++
 hmp.c            |   11 +++++++++++
 hmp.h            |    1 +
 qapi-schema.json |   22 ++++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 6 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index ba973b0..2dfca40 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -947,3 +947,28 @@ void qmp_block_stream(const char *device, bool has_base,
 
     trace_qmp_block_stream(bs, bs->job);
 }
+
+static BlockJob *find_block_job(const char *device)
+{
+    BlockDriverState *bs;
+
+    bs = bdrv_find(device);
+    if (!bs || !bs->job) {
+        return NULL;
+    }
+    return bs->job;
+}
+
+void qmp_block_job_set_speed(const char *device, int64_t value, Error **errp)
+{
+    BlockJob *job = find_block_job(device);
+
+    if (!job) {
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, device);
+        return;
+    }
+
+    if (block_job_set_speed(job, value) < 0) {
+        error_set(errp, QERR_NOT_SUPPORTED);
+    }
+}
diff --git a/hmp-commands.hx b/hmp-commands.hx
index dc6c8c3..12b8433 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -84,6 +84,20 @@ Copy data from a backing file into a block device.
 ETEXI
 
     {
+        .name       = "block_job_set_speed",
+        .args_type  = "device:B,value:o",
+        .params     = "device value",
+        .help       = "set maximum speed for a background block operation",
+        .mhandler.cmd = hmp_block_job_set_speed,
+    },
+
+STEXI
+@item block_job_set_stream
+@findex block_job_set_stream
+Set maximum speed for a background block operation.
+ETEXI
+
+    {
         .name       = "eject",
         .args_type  = "force:-f,device:B",
         .params     = "[-f] device",
diff --git a/hmp.c b/hmp.c
index 85388a2..9544820 100644
--- a/hmp.c
+++ b/hmp.c
@@ -692,3 +692,14 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict)
 
     hmp_handle_error(mon, &error);
 }
+
+void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
+{
+    Error *error = NULL;
+    const char *device = qdict_get_str(qdict, "device");
+    int64_t value = qdict_get_int(qdict, "value");
+
+    qmp_block_job_set_speed(device, value, &error);
+
+    hmp_handle_error(mon, &error);
+}
diff --git a/hmp.h b/hmp.h
index b55c295..2c871ea 100644
--- a/hmp.h
+++ b/hmp.h
@@ -50,5 +50,6 @@ void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_block_stream(Monitor *mon, const QDict *qdict);
+void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index 3821982..5872096 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1307,3 +1307,25 @@
 # Since: 1.1
 ##
 { 'command': 'block_stream', 'data': { 'device': 'str', '*base': 'str' } }
+
+##
+# @block_job_set_speed:
+#
+# Set maximum speed for a background block operation.
+#
+# This command can only be issued when there is an active block job.
+#
+# Throttling can be disabled by setting the speed to 0.
+#
+# @device: the device name
+#
+# @value:  the maximum speed, in bytes per second
+#
+# Returns: Nothing on success
+#          If the job type does not support throttling, NotSupported
+#          If streaming is not active on this device, DeviceNotActive
+#
+# Since: 1.1
+##
+{ 'command': 'block_job_set_speed',
+  'data': { 'device': 'str', 'value': 'int' } }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index b9ebb76..dc6bc2e 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -661,6 +661,12 @@ EQMP
     },
 
     {
+        .name       = "block_job_set_speed",
+        .args_type  = "device:B,value:o",
+        .mhandler.cmd_new = qmp_marshal_input_block_job_set_speed,
+    },
+
+    {
         .name       = "blockdev-snapshot-sync",
         .args_type  = "device:B,snapshot-file:s,format:s?",
         .mhandler.cmd_new = qmp_marshal_input_blockdev_snapshot_sync,
-- 
1.7.8.3

  parent reply	other threads:[~2012-01-18 14:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-18 14:40 [Qemu-devel] [PATCH v6 00/16] block: generic image streaming Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 01/16] coroutine: add co_sleep_ns() coroutine sleep function Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 02/16] block: check bdrv_in_use() before blockdev operations Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 03/16] block: make copy-on-read a per-request flag Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 04/16] block: add BlockJob interface for long-running operations Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 05/16] block: add image streaming block job Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 06/16] block: rate-limit streaming operations Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 07/16] qmp: add block_stream command Stefan Hajnoczi
2012-01-18 14:40 ` Stefan Hajnoczi [this message]
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 09/16] qmp: add block_job_cancel command Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 10/16] qmp: add query-block-jobs Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 11/16] blockdev: make image streaming safe across hotplug Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 12/16] block: add bdrv_find_backing_image Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 13/16] add QERR_BASE_NOT_FOUND Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 14/16] block: add support for partial streaming Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 15/16] docs: describe live block operations Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 16/16] test: add image streaming test cases Stefan Hajnoczi
2012-01-19 14:53 ` [Qemu-devel] [PATCH v6 00/16] block: generic image streaming 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=1326897655-2799-9-git-send-email-stefanha@linux.vnet.ibm.com \
    --to=stefanha@linux.vnet.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).