From patchwork Fri Jan 6 14:01:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 134638 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 86827B6FBD for ; Sat, 7 Jan 2012 01:03:20 +1100 (EST) Received: from localhost ([::1]:57818 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjAO4-0000PN-Qw for incoming@patchwork.ozlabs.org; Fri, 06 Jan 2012 09:03:16 -0500 Received: from eggs.gnu.org ([140.186.70.92]:43821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjANp-0000Ej-80 for qemu-devel@nongnu.org; Fri, 06 Jan 2012 09:03:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RjANj-0001O7-DO for qemu-devel@nongnu.org; Fri, 06 Jan 2012 09:03:01 -0500 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:57537) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjANj-0001Na-6L for qemu-devel@nongnu.org; Fri, 06 Jan 2012 09:02:55 -0500 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 6 Jan 2012 14:02:54 -0000 Received: from d06nrmr1307.portsmouth.uk.ibm.com ([9.149.38.129]) by e06smtp17.uk.ibm.com ([192.168.101.147]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 6 Jan 2012 14:02:51 -0000 Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q06E2pkJ1916948 for ; Fri, 6 Jan 2012 14:02:51 GMT 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 q06E2pJE012639 for ; Fri, 6 Jan 2012 07:02:51 -0700 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.31]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q06E2oKu012632; Fri, 6 Jan 2012 07:02:50 -0700 From: Stefan Hajnoczi To: Date: Fri, 6 Jan 2012 14:01:33 +0000 Message-Id: <1325858501-25741-8-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1325858501-25741-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1325858501-25741-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12010614-0542-0000-0000-000000964EAB X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.113 Cc: Kevin Wolf , Marcelo Tosatti , Stefan Hajnoczi , Luiz Capitulino Subject: [Qemu-devel] [PATCH v4 07/15] 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 | 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 8d9dbd6..5dffcb2 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 b6e5913..1144d53 100644 --- a/hmp.c +++ b/hmp.c @@ -690,3 +690,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 2b1cc8c..7b39371 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,