From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:40109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJRp4-0003pR-LT for qemu-devel@nongnu.org; Thu, 27 Oct 2011 11:24:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJRoz-0005b8-GW for qemu-devel@nongnu.org; Thu, 27 Oct 2011 11:24:50 -0400 Received: from mtagate2.uk.ibm.com ([194.196.100.162]:54221) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJRoz-0005GO-4k for qemu-devel@nongnu.org; Thu, 27 Oct 2011 11:24:45 -0400 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate2.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p9RFNMUp003209 for ; Thu, 27 Oct 2011 15:23:22 GMT Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p9RFNMJ82502764 for ; Thu, 27 Oct 2011 16:23:22 +0100 Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p9RFNMgM001524 for ; Thu, 27 Oct 2011 09:23:22 -0600 From: Stefan Hajnoczi Date: Thu, 27 Oct 2011 16:22:52 +0100 Message-Id: <1319728975-6069-6-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1319728975-6069-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1319728975-6069-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 5/8] qmp: add block_job_set_speed command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Anthony Liguori , Marcelo Tosatti , Stefan Hajnoczi Add block_job_set_speed, which sets the maximum speed for a background block operation. Signed-off-by: Stefan Hajnoczi --- blockdev.c | 33 +++++++++++++++++++++++++++++++++ blockdev.h | 2 ++ hmp-commands.hx | 15 +++++++++++++++ qmp-commands.hx | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 0 deletions(-) diff --git a/blockdev.c b/blockdev.c index de911de..781825b 100644 --- a/blockdev.c +++ b/blockdev.c @@ -851,3 +851,36 @@ int do_block_stream(Monitor *mon, const QDict *params, QObject **ret_data) trace_do_block_stream(bs, bs->job); return 0; } + +static BlockJob *find_block_job(const char *device) +{ + BlockDriverState *bs; + + bs = bdrv_find(device); + if (!bs || !bs->job) { + return NULL; + } + return bs->job; +} + +int do_block_job_set_speed(Monitor *mon, const QDict *params, + QObject **ret_data) +{ + const char *device = qdict_get_str(params, "device"); + BlockJob *job = find_block_job(device); + int64_t value; + int ret; + + if (!job) { + qerror_report(QERR_DEVICE_NOT_ACTIVE, device); + return -1; + } + + value = qdict_get_int(params, "value"); + ret = block_job_set_speed(job, value); + if (ret == -ENOTSUP) { + qerror_report(QERR_NOT_SUPPORTED); + return -1; + } + return 0; +} diff --git a/blockdev.h b/blockdev.h index ad98d37..6b48405 100644 --- a/blockdev.h +++ b/blockdev.h @@ -66,5 +66,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_block_stream(Monitor *mon, const QDict *qdict, QObject **ret_data); +int do_block_job_set_speed(Monitor *mon, const QDict *qdict, + QObject **ret_data); #endif diff --git a/hmp-commands.hx b/hmp-commands.hx index 2aeb2e0..2cdfa0b 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -86,6 +86,21 @@ 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", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_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/qmp-commands.hx b/qmp-commands.hx index 31cde4b..6cfb548 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -750,6 +750,41 @@ Examples: EQMP { + .name = "block_job_set_speed", + .args_type = "device:B,value:o", + .params = "device value", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_block_job_set_speed, + }, + +SQMP + +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. + +Arguments: + +- device: device name (json-string) +- value: maximum speed, in bytes per second (json-int) + +Errors: +NotSupported: job type does not support speed setting +DeviceNotActive: streaming is not active on this device + +Example: + +-> { "execute": "block_job_set_speed", + "arguments": { "device": "virtio0", "value": 1024 } } + +EQMP + + { .name = "blockdev-snapshot-sync", .args_type = "device:B,snapshot-file:s?,format:s?", .params = "device [new-image-file] [format]", -- 1.7.7