@@ -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);
}
@@ -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) {
@@ -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:
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 <armbru@redhat.com> --- blockdev.c | 6 ++++++ blockjob.c | 14 +++++++------- include/block/blockjob.h | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-)