@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
@@ -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;
@@ -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;
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 <armbru@redhat.com> --- 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(-)