From patchwork Mon Aug 7 14:45:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 9885523 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DD000603B4 for ; Mon, 7 Aug 2017 14:55:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE693285DB for ; Mon, 7 Aug 2017 14:55:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C346228671; Mon, 7 Aug 2017 14:55:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4503E285DB for ; Mon, 7 Aug 2017 14:55:56 +0000 (UTC) Received: from localhost ([::1]:37728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dejRj-0005sr-Fj for patchwork-qemu-devel@patchwork.kernel.org; Mon, 07 Aug 2017 10:55:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dejJ9-0007RX-Lw for qemu-devel@nongnu.org; Mon, 07 Aug 2017 10:47:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dejIu-0003y7-2z for qemu-devel@nongnu.org; Mon, 07 Aug 2017 10:47:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56214) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dejIW-0003aN-4C; Mon, 07 Aug 2017 10:46:24 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0222E356E2; Mon, 7 Aug 2017 14:46:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0222E356E2 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=armbru@redhat.com Received: from blackfin.pond.sub.org (ovpn-116-254.ams2.redhat.com [10.36.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 77A8568D96; Mon, 7 Aug 2017 14:46:22 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 81E6911385DC; Mon, 7 Aug 2017 16:46:00 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 7 Aug 2017 16:45:39 +0200 Message-Id: <1502117160-24655-36-git-send-email-armbru@redhat.com> In-Reply-To: <1502117160-24655-1-git-send-email-armbru@redhat.com> References: <1502117160-24655-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 07 Aug 2017 14:46:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 35/56] blockjob: Lift speed sign conversion into block_job_set_speed() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, quintela@redhat.com, jcody@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The BlockJob abstraction takes int64_t speed. The underlying RateLimit abstraction takes uint64_t. We convert from int64_t to uint64_t in the BlockJobDriver speed_set() methods. They all reject negative speed. Lift this check and conversion up into the method's caller block_job_set_speed(). I'm going to lift it further until it falls off the top. Improve the error message while there. Signed-off-by: Markus Armbruster --- block/backup.c | 6 +----- block/commit.c | 6 +----- block/mirror.c | 6 +----- block/stream.c | 6 +----- blockjob.c | 7 +++++++ include/block/blockjob.h | 2 +- include/block/blockjob_int.h | 2 +- 7 files changed, 13 insertions(+), 22 deletions(-) diff --git a/block/backup.c b/block/backup.c index a37c944..b76143d 100644 --- a/block/backup.c +++ b/block/backup.c @@ -188,14 +188,10 @@ static int coroutine_fn backup_before_write_notify( return backup_do_cow(job, req->offset, req->bytes, NULL, true); } -static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp) +static void backup_set_speed(BlockJob *job, uint64_t speed, Error **errp) { BackupBlockJob *s = container_of(job, BackupBlockJob, common); - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } diff --git a/block/commit.c b/block/commit.c index c7857c3..5dc1c73 100644 --- a/block/commit.c +++ b/block/commit.c @@ -220,14 +220,10 @@ out: block_job_defer_to_main_loop(&s->common, commit_complete, data); } -static void commit_set_speed(BlockJob *job, int64_t speed, Error **errp) +static void commit_set_speed(BlockJob *job, uint64_t speed, Error **errp) { CommitBlockJob *s = container_of(job, CommitBlockJob, common); - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } diff --git a/block/mirror.c b/block/mirror.c index 37a8744..7959a7f 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -928,14 +928,10 @@ immediate_exit: block_job_defer_to_main_loop(&s->common, mirror_exit, data); } -static void mirror_set_speed(BlockJob *job, int64_t speed, Error **errp) +static void mirror_set_speed(BlockJob *job, uint64_t speed, Error **errp) { MirrorBlockJob *s = container_of(job, MirrorBlockJob, common); - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } diff --git a/block/stream.c b/block/stream.c index e6f7234..11b6673 100644 --- a/block/stream.c +++ b/block/stream.c @@ -207,14 +207,10 @@ out: block_job_defer_to_main_loop(&s->common, stream_complete, data); } -static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp) +static void stream_set_speed(BlockJob *job, uint64_t speed, Error **errp) { StreamBlockJob *s = container_of(job, StreamBlockJob, common); - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } diff --git a/blockjob.c b/blockjob.c index 70a7818..7f77b7e 100644 --- a/blockjob.c +++ b/blockjob.c @@ -460,6 +460,13 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp) error_setg(errp, QERR_UNSUPPORTED); return; } + + if (speed < 0) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "speed", + "a non-negative rate limit"); + return; + } + job->driver->set_speed(job, speed, &local_err); if (local_err) { error_propagate(errp, local_err); diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 67c0968..bf5314b 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -110,7 +110,7 @@ typedef struct BlockJob { int64_t len; /** Speed that was set with @block_job_set_speed. */ - int64_t speed; + uint64_t speed; /** The completion function that will be called when the job completes. */ BlockCompletionFunc *cb; diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index f13ad05..2d10794 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -42,7 +42,7 @@ struct BlockJobDriver { BlockJobType job_type; /** Optional callback for job types that support setting a speed limit */ - void (*set_speed)(BlockJob *job, int64_t speed, Error **errp); + void (*set_speed)(BlockJob *job, uint64_t speed, Error **errp); /** Mandatory: Entrypoint for the Coroutine. */ CoroutineEntry *start;