From patchwork Wed Jan 18 14:40:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 136622 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 A8995100A24 for ; Thu, 19 Jan 2012 01:41:42 +1100 (EST) Received: from localhost ([::1]:37024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RnWhn-000260-Ou for incoming@patchwork.ozlabs.org; Wed, 18 Jan 2012 09:41:39 -0500 Received: from eggs.gnu.org ([140.186.70.92]:44788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RnWhW-0001Yy-EJ for qemu-devel@nongnu.org; Wed, 18 Jan 2012 09:41:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RnWhR-0007nV-4M for qemu-devel@nongnu.org; Wed, 18 Jan 2012 09:41:22 -0500 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:56656) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RnWhQ-0007nF-SF for qemu-devel@nongnu.org; Wed, 18 Jan 2012 09:41:17 -0500 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 18 Jan 2012 14:41:16 -0000 Received: from d06nrmr1507.portsmouth.uk.ibm.com ([9.149.38.233]) by e06smtp13.uk.ibm.com ([192.168.101.143]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 18 Jan 2012 14:41:14 -0000 Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q0IEfDl52293922 for ; Wed, 18 Jan 2012 14:41:13 GMT Received: from d06av09.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q0IEfCkq008699 for ; Wed, 18 Jan 2012 07:41:13 -0700 Received: from localhost (sig-9-145-203-19.de.ibm.com [9.145.203.19]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q0IEfBR4008661; Wed, 18 Jan 2012 07:41:11 -0700 From: Stefan Hajnoczi To: Date: Wed, 18 Jan 2012 14:40:47 +0000 Message-Id: <1326897655-2799-9-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.8.3 In-Reply-To: <1326897655-2799-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1326897655-2799-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12011814-2966-0000-0000-000002F18E1C X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.109 Cc: Kevin Wolf , Marcelo Tosatti , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v6 08/16] 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 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,