From patchwork Tue Apr 24 13:53:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 154689 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9A785B6EE7 for ; Wed, 25 Apr 2012 00:44:17 +1000 (EST) Received: from localhost ([::1]:41187 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SMgD4-0006nB-Oa for incoming@patchwork.ozlabs.org; Tue, 24 Apr 2012 09:55:14 -0400 Received: from eggs.gnu.org ([208.118.235.92]:32979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SMgCQ-0005QX-V1 for qemu-devel@nongnu.org; Tue, 24 Apr 2012 09:54:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SMgCK-0000Lm-Ev for qemu-devel@nongnu.org; Tue, 24 Apr 2012 09:54:34 -0400 Received: from e06smtp14.uk.ibm.com ([195.75.94.110]:50773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SMgCK-0000GX-6H for qemu-devel@nongnu.org; Tue, 24 Apr 2012 09:54:28 -0400 Received: from /spool/local by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 24 Apr 2012 14:54:24 +0100 Received: from d06nrmr1707.portsmouth.uk.ibm.com (9.149.39.225) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 24 Apr 2012 14:54:12 +0100 Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q3ODsAau2482370 for ; Tue, 24 Apr 2012 14:54:12 +0100 Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q3ODs9dT013461 for ; Tue, 24 Apr 2012 07:54:09 -0600 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.241]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q3ODs9j9013456; Tue, 24 Apr 2012 07:54:09 -0600 From: Stefan Hajnoczi To: Date: Tue, 24 Apr 2012 14:53:56 +0100 Message-Id: <1335275640-3349-3-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1335275640-3349-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1335275640-3349-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12042413-1948-0000-0000-0000019CEDAF X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.110 Cc: Kevin Wolf , Paolo Bonzini , Eric Blake , Stefan Hajnoczi , Luiz Capitulino Subject: [Qemu-devel] [PATCH v2 2/6] block: use Error mechanism instead of -errno for block_job_set_speed() 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 There are at least two different errors that can occur in block_job_set_speed(): the job might not support setting speeds or the value might be invalid. Use the Error mechanism to report the error where it occurs. Cc: Luiz Capitulino Signed-off-by: Stefan Hajnoczi --- block.c | 17 ++++++++++------- block/stream.c | 6 +++--- block_int.h | 5 +++-- blockdev.c | 4 +--- qapi-schema.json | 1 + 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index 2b72a0f..dc02736 100644 --- a/block.c +++ b/block.c @@ -4114,18 +4114,21 @@ void block_job_complete(BlockJob *job, int ret) bdrv_set_in_use(bs, 0); } -int block_job_set_speed(BlockJob *job, int64_t value) +void block_job_set_speed(BlockJob *job, int64_t value, Error **errp) { - int rc; + Error *local_err = NULL; if (!job->job_type->set_speed) { - return -ENOTSUP; + error_set(errp, QERR_NOT_SUPPORTED); + return; } - rc = job->job_type->set_speed(job, value); - if (rc == 0) { - job->speed = value; + job->job_type->set_speed(job, value, &local_err); + if (error_is_set(&local_err)) { + error_propagate(errp, local_err); + return; } - return rc; + + job->speed = value; } void block_job_cancel(BlockJob *job) diff --git a/block/stream.c b/block/stream.c index 7002dc8..06bc70a 100644 --- a/block/stream.c +++ b/block/stream.c @@ -263,15 +263,15 @@ retry: block_job_complete(&s->common, ret); } -static int stream_set_speed(BlockJob *job, int64_t value) +static void stream_set_speed(BlockJob *job, int64_t value, Error **errp) { StreamBlockJob *s = container_of(job, StreamBlockJob, common); if (value < 0) { - return -EINVAL; + error_set(errp, QERR_INVALID_PARAMETER, "value"); + return; } ratelimit_set_speed(&s->limit, value / BDRV_SECTOR_SIZE); - return 0; } static BlockJobType stream_job_type = { diff --git a/block_int.h b/block_int.h index 8cf6ce9..f8e6592 100644 --- a/block_int.h +++ b/block_int.h @@ -79,7 +79,7 @@ typedef struct BlockJobType { const char *job_type; /** Optional callback for job types that support setting a speed limit */ - int (*set_speed)(BlockJob *job, int64_t value); + void (*set_speed)(BlockJob *job, int64_t value, Error **errp); } BlockJobType; /** @@ -375,11 +375,12 @@ void block_job_complete(BlockJob *job, int ret); * block_job_set_speed: * @job: The job to set the speed for. * @speed: The new value + * @errp: A location to return NotSupported or BlockJobSpeedInvalid. * * Set a rate-limiting parameter for the job; the actual meaning may * vary depending on the job type. */ -int block_job_set_speed(BlockJob *job, int64_t value); +void block_job_set_speed(BlockJob *job, int64_t value, Error **errp); /** * block_job_cancel: diff --git a/blockdev.c b/blockdev.c index a411477..7073330 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1145,9 +1145,7 @@ void qmp_block_job_set_speed(const char *device, int64_t value, Error **errp) return; } - if (block_job_set_speed(job, value) < 0) { - error_set(errp, QERR_NOT_SUPPORTED); - } + block_job_set_speed(job, value, errp); } void qmp_block_job_cancel(const char *device, Error **errp) diff --git a/qapi-schema.json b/qapi-schema.json index 6499895..49f1e16 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1596,6 +1596,7 @@ # # Returns: Nothing on success # If the job type does not support throttling, NotSupported +# If the speed value is invalid, InvalidParameter # If streaming is not active on this device, DeviceNotActive # # Since: 1.1