From patchwork Mon Aug 7 14:45:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 798692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xR14j33CHz9s03 for ; Tue, 8 Aug 2017 01:03:33 +1000 (AEST) Received: from localhost ([::1]:37775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dejZ5-0005RL-8A for incoming@patchwork.ozlabs.org; Mon, 07 Aug 2017 11:03:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dejJB-0007UI-QB for qemu-devel@nongnu.org; Mon, 07 Aug 2017 10:47:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dejIv-0003zu-MQ for qemu-devel@nongnu.org; Mon, 07 Aug 2017 10:47:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dejIW-0003bq-P3; Mon, 07 Aug 2017 10:46:25 -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 923DE806C3; Mon, 7 Aug 2017 14:46:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 923DE806C3 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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 B1FAC69297; Mon, 7 Aug 2017 14:46:22 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8FE3F11384C6; Mon, 7 Aug 2017 16:46:00 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 7 Aug 2017 16:45:43 +0200 Message-Id: <1502117160-24655-40-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.26]); 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 39/56] blockjob: Lift speed sign conversion out of block_job_create() 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" block_job_create() takes int64_t speed. The underlying RateLimit abstraction takes uint64_t. block_job_create() converts from int64_t to uint64_t, rejecting negative speed. Lift this check and conversion out of block_job_create() into its callers. I'm going to lift it further until it falls off the top. Signed-off-by: Markus Armbruster --- block/backup.c | 5 +++++ block/commit.c | 6 ++++++ block/mirror.c | 6 ++++++ block/stream.c | 6 ++++++ blockjob.c | 8 +------- include/block/blockjob_int.h | 2 +- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/block/backup.c b/block/backup.c index 359e526..3a97836 100644 --- a/block/backup.c +++ b/block/backup.c @@ -577,6 +577,11 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, return NULL; } + if (speed < 0) { + error_setg(errp, QERR_INVALID_PARAMETER, "speed"); + return NULL; + } + if (sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) { if (!sync_bitmap) { error_setg(errp, "must provide a valid bitmap name for " diff --git a/block/commit.c b/block/commit.c index ae9191d..86d780e 100644 --- a/block/commit.c +++ b/block/commit.c @@ -309,6 +309,12 @@ void commit_start(const char *job_id, BlockDriverState *bs, return; } + if (speed < 0) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "speed", + "a non-negative rate limit"); + return; + } + s = block_job_create(job_id, &commit_job_driver, bs, 0, BLK_PERM_ALL, speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp); if (!s) { diff --git a/block/mirror.c b/block/mirror.c index 6c3b446..af54163 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1139,6 +1139,12 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs, Error *local_err = NULL; int ret; + if (speed < 0) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "speed", + "a non-negative rate limit"); + return; + } + if (granularity == 0) { granularity = bdrv_get_default_bitmap_granularity(target); } diff --git a/block/stream.c b/block/stream.c index 9a145f2..fefcdb9 100644 --- a/block/stream.c +++ b/block/stream.c @@ -237,6 +237,12 @@ void stream_start(const char *job_id, BlockDriverState *bs, } } + if (speed < 0) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "speed", + "a non-negative rate limit"); + return; + } + /* Prevent concurrent jobs trying to modify the graph structure here, we * already have our own plans. Also don't allow resize as the image size is * queried only at the job start and then cached. */ diff --git a/blockjob.c b/blockjob.c index 998ffef..335099e 100644 --- a/blockjob.c +++ b/blockjob.c @@ -604,7 +604,7 @@ static void block_job_event_completed(BlockJob *job, const char *msg) void *block_job_create(const char *job_id, const BlockJobDriver *driver, BlockDriverState *bs, uint64_t perm, - uint64_t shared_perm, int64_t speed, int flags, + uint64_t shared_perm, uint64_t speed, int flags, BlockCompletionFunc *cb, void *opaque, Error **errp) { BlockBackend *blk; @@ -641,12 +641,6 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, } } - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "speed", - "a non-negative rate limit"); - return NULL; - } - blk = blk_new(perm, shared_perm); ret = blk_insert_bs(blk, bs, errp); if (ret < 0) { diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index dadfd8c..33472ba 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -133,7 +133,7 @@ struct BlockJobDriver { */ void *block_job_create(const char *job_id, const BlockJobDriver *driver, BlockDriverState *bs, uint64_t perm, - uint64_t shared_perm, int64_t speed, int flags, + uint64_t shared_perm, uint64_t speed, int flags, BlockCompletionFunc *cb, void *opaque, Error **errp); /**