From patchwork Tue Dec 13 13:52:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 131097 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 984B61007D3 for ; Wed, 14 Dec 2011 00:55:19 +1100 (EST) Received: from localhost ([::1]:53700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaSp9-0002KC-Tp for incoming@patchwork.ozlabs.org; Tue, 13 Dec 2011 08:55:15 -0500 Received: from eggs.gnu.org ([140.186.70.92]:55322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaSou-00021f-5m for qemu-devel@nongnu.org; Tue, 13 Dec 2011 08:55:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaSol-0004Ch-GG for qemu-devel@nongnu.org; Tue, 13 Dec 2011 08:55:00 -0500 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:50836) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaSol-0004CR-9K for qemu-devel@nongnu.org; Tue, 13 Dec 2011 08:54:51 -0500 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Dec 2011 13:54:50 -0000 Received: from d06nrmr1307.portsmouth.uk.ibm.com ([9.149.38.129]) by e06smtp15.uk.ibm.com ([192.168.101.145]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 13 Dec 2011 13:54:48 -0000 Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pBDDsllP2367640 for ; Tue, 13 Dec 2011 13:54:47 GMT Received: from d06av04.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pBDDslu0019326 for ; Tue, 13 Dec 2011 06:54:47 -0700 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.31]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id pBDDslKP019323; Tue, 13 Dec 2011 06:54:47 -0700 From: Stefan Hajnoczi To: Date: Tue, 13 Dec 2011 13:52:28 +0000 Message-Id: <1323784351-25531-7-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1323784351-25531-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1323784351-25531-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 11121313-0342-0000-0000-000000550F7C X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.111 Cc: Kevin Wolf , Marcelo Tosatti , Stefan Hajnoczi , Luiz Capitulino Subject: [Qemu-devel] [PATCH v3 6/9] qmp: add block_job_set_speed command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add block_job_set_speed, which sets the maximum speed for a background block operation. Signed-off-by: Stefan Hajnoczi --- blockdev.c | 25 +++++++++++++++++++++++++ hmp-commands.hx | 14 ++++++++++++++ hmp.c | 14 ++++++++++++++ hmp.h | 1 + qapi-schema.json | 23 +++++++++++++++++++++++ qmp-commands.hx | 18 ++++++++++++++++++ 6 files changed, 95 insertions(+), 0 deletions(-) diff --git a/blockdev.c b/blockdev.c index 08355cf..b101ba1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -955,3 +955,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 c0de41c..788ec97 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -85,6 +85,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 8b7d7d4..f3edf7c 100644 --- a/hmp.c +++ b/hmp.c @@ -545,3 +545,17 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict) error_free(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); + + if (error) { + monitor_printf(mon, "%s\n", error_get_pretty(error)); + error_free(error); + } +} diff --git a/hmp.h b/hmp.h index 3cb6fe5..4c1458e 100644 --- a/hmp.h +++ b/hmp.h @@ -38,5 +38,6 @@ void hmp_system_reset(Monitor *mon, const QDict *qdict); void hmp_system_powerdown(Monitor *mon, const QDict *qdict); void hmp_cpu(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 65308d2..f6a8252 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -954,3 +954,26 @@ # 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. +# +# Arguments: +# +# - device: device name +# - value: maximum speed, in bytes per second +# +# Errors: +# NotSupported: job type does not support speed setting +# DeviceNotActive: streaming is not active on this device +# +# Since: 1.1 +## +{ 'command': 'block_job_set_speed', + 'data': { 'device': 'str', 'value': 'int' } } diff --git a/qmp-commands.hx b/qmp-commands.hx index 8c1c934..5541ca0 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -701,6 +701,24 @@ Examples: EQMP { + .name = "block_job_set_speed", + .args_type = "device:B,value:o", + .mhandler.cmd_new = qmp_marshal_input_block_job_set_speed, + }, + +SQMP +block_job_set_speed +------------------- +See qapi-schema.json for documentation. + +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]",