aboutsummaryrefslogtreecommitdiff
path: root/blockjob.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-01-18 20:25:40 +0100
committerKevin Wolf <kwolf@redhat.com>2018-05-15 16:11:50 +0200
commit18bb69287ea522ab696e1bea818b93e5eaa85745 (patch)
tree881877ce730553c75abcf6bf5a2aa50870993874 /blockjob.c
parentf05fee508f538ca262d2ab19bcd8772196efe848 (diff)
blockjob: Implement block_job_set_speed() centrally
All block job drivers support .set_speed and all of them duplicate the same code to implement it. Move that code to blockjob.c and remove the now useless callback. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'blockjob.c')
-rw-r--r--blockjob.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/blockjob.c b/blockjob.c
index ebc26a5245..2f4b768338 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -659,22 +659,18 @@ static bool block_job_timer_pending(BlockJob *job)
void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
{
- Error *local_err = NULL;
int64_t old_speed = job->speed;
- if (!job->driver->set_speed) {
- error_setg(errp, QERR_UNSUPPORTED);
- return;
- }
if (block_job_apply_verb(job, BLOCK_JOB_VERB_SET_SPEED, errp)) {
return;
}
- job->driver->set_speed(job, speed, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ if (speed < 0) {
+ error_setg(errp, QERR_INVALID_PARAMETER, "speed");
return;
}
+ ratelimit_set_speed(&job->limit, speed, BLOCK_JOB_SLICE_TIME);
+
job->speed = speed;
if (speed && speed <= old_speed) {
return;