From nobody Mon Feb 9 02:27:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502117787509900.7591893656985; Mon, 7 Aug 2017 07:56:27 -0700 (PDT) Received: from localhost ([::1]:37737 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dejSE-0007O7-3s for importer@patchew.org; Mon, 07 Aug 2017 10:56:26 -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) 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) 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 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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); } =20 -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 =3D container_of(job, BackupBlockJob, common); =20 - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 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); } =20 -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 =3D container_of(job, CommitBlockJob, common); =20 - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 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); } =20 -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 =3D container_of(job, MirrorBlockJob, common); =20 - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 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); } =20 -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 =3D container_of(job, StreamBlockJob, common); =20 - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 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; =20 /** Speed that was set with @block_job_set_speed. */ - int64_t speed; + uint64_t speed; =20 /** 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; =20 /** 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); =20 /** Mandatory: Entrypoint for the Coroutine. */ CoroutineEntry *start; --=20 2.7.5