The BlockJob abstraction takes int64_t speed. The underlying RateLimit abstraction takes uint64_t. We convert from int64_t to uint64_t in block_job_set_speed(). It rejects negative speed.
Lift this check and conversion up into its callers qmp_block_job_set_speed() and block_job_create(). I'm going to lift it further until it falls off the top. Signed-off-by: Markus Armbruster <arm...@redhat.com> --- blockdev.c | 6 ++++++ blockjob.c | 14 +++++++------- include/block/blockjob.h | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/blockdev.c b/blockdev.c index 98dbe51..f9afc32 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3697,6 +3697,12 @@ void qmp_block_job_set_speed(const char *device, int64_t speed, Error **errp) return; } + if (speed < 0) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "speed", + "a non-negative rate limit"); + return; + } + block_job_set_speed(job, speed, errp); aio_context_release(aio_context); } diff --git a/blockjob.c b/blockjob.c index e653eef..998ffef 100644 --- a/blockjob.c +++ b/blockjob.c @@ -452,19 +452,13 @@ static void block_job_completed_txn_success(BlockJob *job) } } -void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp) +void block_job_set_speed(BlockJob *job, uint64_t speed, Error **errp) { if (!job->driver->set_speed) { 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); job->speed = speed; } @@ -647,6 +641,12 @@ 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.h b/include/block/blockjob.h index bf5314b..5eb1537 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -198,7 +198,7 @@ void block_job_remove_all_bdrv(BlockJob *job); * Set a rate-limiting parameter for the job; the actual meaning may * vary depending on the job type. */ -void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp); +void block_job_set_speed(BlockJob *job, uint64_t speed, Error **errp); /** * block_job_start: -- 2.7.5