blockjob: introduce block_job _locked() APIs
Just as done with job.h, create _locked() functions in blockjob.h These functions will be later useful when caller has already taken the lock. All blockjob _locked functions call job _locked functions. Note: at this stage, job_{lock/unlock} and job lock guard macros are *nop*. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20220926093214.506243-8-eesposit@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
bf61c583fc
commit
f41ab73fa2
52
blockjob.c
52
blockjob.c
@ -44,21 +44,27 @@ static bool is_block_job(Job *job)
|
||||
job_type(job) == JOB_TYPE_STREAM;
|
||||
}
|
||||
|
||||
BlockJob *block_job_next(BlockJob *bjob)
|
||||
BlockJob *block_job_next_locked(BlockJob *bjob)
|
||||
{
|
||||
Job *job = bjob ? &bjob->job : NULL;
|
||||
GLOBAL_STATE_CODE();
|
||||
|
||||
do {
|
||||
job = job_next(job);
|
||||
job = job_next_locked(job);
|
||||
} while (job && !is_block_job(job));
|
||||
|
||||
return job ? container_of(job, BlockJob, job) : NULL;
|
||||
}
|
||||
|
||||
BlockJob *block_job_get(const char *id)
|
||||
BlockJob *block_job_next(BlockJob *bjob)
|
||||
{
|
||||
Job *job = job_get(id);
|
||||
JOB_LOCK_GUARD();
|
||||
return block_job_next_locked(bjob);
|
||||
}
|
||||
|
||||
BlockJob *block_job_get_locked(const char *id)
|
||||
{
|
||||
Job *job = job_get_locked(id);
|
||||
GLOBAL_STATE_CODE();
|
||||
|
||||
if (job && is_block_job(job)) {
|
||||
@ -68,6 +74,12 @@ BlockJob *block_job_get(const char *id)
|
||||
}
|
||||
}
|
||||
|
||||
BlockJob *block_job_get(const char *id)
|
||||
{
|
||||
JOB_LOCK_GUARD();
|
||||
return block_job_get_locked(id);
|
||||
}
|
||||
|
||||
void block_job_free(Job *job)
|
||||
{
|
||||
BlockJob *bjob = container_of(job, BlockJob, job);
|
||||
@ -256,14 +268,14 @@ static bool job_timer_pending(Job *job)
|
||||
return timer_pending(&job->sleep_timer);
|
||||
}
|
||||
|
||||
bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
||||
bool block_job_set_speed_locked(BlockJob *job, int64_t speed, Error **errp)
|
||||
{
|
||||
const BlockJobDriver *drv = block_job_driver(job);
|
||||
int64_t old_speed = job->speed;
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
|
||||
if (job_apply_verb(&job->job, JOB_VERB_SET_SPEED, errp) < 0) {
|
||||
if (job_apply_verb_locked(&job->job, JOB_VERB_SET_SPEED, errp) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (speed < 0) {
|
||||
@ -277,7 +289,9 @@ bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
||||
job->speed = speed;
|
||||
|
||||
if (drv->set_speed) {
|
||||
job_unlock();
|
||||
drv->set_speed(job, speed);
|
||||
job_lock();
|
||||
}
|
||||
|
||||
if (speed && speed <= old_speed) {
|
||||
@ -285,18 +299,24 @@ bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
||||
}
|
||||
|
||||
/* kick only if a timer is pending */
|
||||
job_enter_cond(&job->job, job_timer_pending);
|
||||
job_enter_cond_locked(&job->job, job_timer_pending);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
||||
{
|
||||
JOB_LOCK_GUARD();
|
||||
return block_job_set_speed_locked(job, speed, errp);
|
||||
}
|
||||
|
||||
int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n)
|
||||
{
|
||||
IO_CODE();
|
||||
return ratelimit_calculate_delay(&job->limit, n);
|
||||
}
|
||||
|
||||
BlockJobInfo *block_job_query(BlockJob *job, Error **errp)
|
||||
BlockJobInfo *block_job_query_locked(BlockJob *job, Error **errp)
|
||||
{
|
||||
BlockJobInfo *info;
|
||||
uint64_t progress_current, progress_total;
|
||||
@ -320,7 +340,7 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **errp)
|
||||
info->len = progress_total;
|
||||
info->speed = job->speed;
|
||||
info->io_status = job->iostatus;
|
||||
info->ready = job_is_ready(&job->job),
|
||||
info->ready = job_is_ready_locked(&job->job),
|
||||
info->status = job->job.status;
|
||||
info->auto_finalize = job->job.auto_finalize;
|
||||
info->auto_dismiss = job->job.auto_dismiss;
|
||||
@ -333,6 +353,12 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **errp)
|
||||
return info;
|
||||
}
|
||||
|
||||
BlockJobInfo *block_job_query(BlockJob *job, Error **errp)
|
||||
{
|
||||
JOB_LOCK_GUARD();
|
||||
return block_job_query_locked(job, errp);
|
||||
}
|
||||
|
||||
static void block_job_iostatus_set_err(BlockJob *job, int error)
|
||||
{
|
||||
if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
|
||||
@ -478,7 +504,7 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void block_job_iostatus_reset(BlockJob *job)
|
||||
void block_job_iostatus_reset_locked(BlockJob *job)
|
||||
{
|
||||
GLOBAL_STATE_CODE();
|
||||
if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
|
||||
@ -488,6 +514,12 @@ void block_job_iostatus_reset(BlockJob *job)
|
||||
job->iostatus = BLOCK_DEVICE_IO_STATUS_OK;
|
||||
}
|
||||
|
||||
void block_job_iostatus_reset(BlockJob *job)
|
||||
{
|
||||
JOB_LOCK_GUARD();
|
||||
block_job_iostatus_reset_locked(job);
|
||||
}
|
||||
|
||||
void block_job_user_resume(Job *job)
|
||||
{
|
||||
BlockJob *bjob = container_of(job, BlockJob, job);
|
||||
|
@ -92,6 +92,9 @@ typedef struct BlockJob {
|
||||
*/
|
||||
BlockJob *block_job_next(BlockJob *job);
|
||||
|
||||
/* Same as block_job_next(), but called with job lock held. */
|
||||
BlockJob *block_job_next_locked(BlockJob *job);
|
||||
|
||||
/**
|
||||
* block_job_get:
|
||||
* @id: The id of the block job.
|
||||
@ -102,6 +105,9 @@ BlockJob *block_job_next(BlockJob *job);
|
||||
*/
|
||||
BlockJob *block_job_get(const char *id);
|
||||
|
||||
/* Same as block_job_get(), but called with job lock held. */
|
||||
BlockJob *block_job_get_locked(const char *id);
|
||||
|
||||
/**
|
||||
* block_job_add_bdrv:
|
||||
* @job: A block job
|
||||
@ -145,6 +151,12 @@ bool block_job_has_bdrv(BlockJob *job, BlockDriverState *bs);
|
||||
*/
|
||||
bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp);
|
||||
|
||||
/*
|
||||
* Same as block_job_set_speed(), but called with job lock held.
|
||||
* Might release the lock temporarily.
|
||||
*/
|
||||
bool block_job_set_speed_locked(BlockJob *job, int64_t speed, Error **errp);
|
||||
|
||||
/**
|
||||
* block_job_query:
|
||||
* @job: The job to get information about.
|
||||
@ -153,6 +165,9 @@ bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp);
|
||||
*/
|
||||
BlockJobInfo *block_job_query(BlockJob *job, Error **errp);
|
||||
|
||||
/* Same as block_job_query(), but called with job lock held. */
|
||||
BlockJobInfo *block_job_query_locked(BlockJob *job, Error **errp);
|
||||
|
||||
/**
|
||||
* block_job_iostatus_reset:
|
||||
* @job: The job whose I/O status should be reset.
|
||||
@ -162,6 +177,9 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **errp);
|
||||
*/
|
||||
void block_job_iostatus_reset(BlockJob *job);
|
||||
|
||||
/* Same as block_job_iostatus_reset(), but called with job lock held. */
|
||||
void block_job_iostatus_reset_locked(BlockJob *job);
|
||||
|
||||
/*
|
||||
* block_job_get_aio_context:
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user