Skip to content

Commit

Permalink
blockjob: return status from block_job_set_speed()
Browse files Browse the repository at this point in the history
Better to return status together with setting errp. It allows to avoid
error propagation in the caller.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Message-Id: <20210202124956.63146-8-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
  • Loading branch information
Vladimir Sementsov-Ogievskiy authored and ebblake committed Mar 8, 2021
1 parent eb5becc commit 775d0c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions blockjob.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,18 @@ static bool job_timer_pending(Job *job)
return timer_pending(&job->sleep_timer);
}

void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
{
const BlockJobDriver *drv = block_job_driver(job);
int64_t old_speed = job->speed;

if (job_apply_verb(&job->job, JOB_VERB_SET_SPEED, errp)) {
return;
if (job_apply_verb(&job->job, JOB_VERB_SET_SPEED, errp) < 0) {
return false;
}
if (speed < 0) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "speed",
"a non-negative value");
return;
return false;
}

ratelimit_set_speed(&job->limit, speed, BLOCK_JOB_SLICE_TIME);
Expand All @@ -281,11 +281,13 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
}

if (speed && speed <= old_speed) {
return;
return true;
}

/* kick only if a timer is pending */
job_enter_cond(&job->job, job_timer_pending);

return true;
}

int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n)
Expand Down Expand Up @@ -458,12 +460,8 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,

/* Only set speed when necessary to avoid NotSupported error */
if (speed != 0) {
Error *local_err = NULL;

block_job_set_speed(job, speed, &local_err);
if (local_err) {
if (!block_job_set_speed(job, speed, errp)) {
job_early_fail(&job->job);
error_propagate(errp, local_err);
return NULL;
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/block/blockjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bool block_job_has_bdrv(BlockJob *job, BlockDriverState *bs);
* 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);
bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp);

/**
* block_job_query:
Expand Down

0 comments on commit 775d0c0

Please sign in to comment.