blockjob: add block_job_release function

There is job resource leak in function mirror_start_job,
although bdrv_create_dirty_bitmap is unlikely failed.
Add block_job_release for each release when needed.

Signed-off-by: Ting Wang <kathy.wangting@huawei.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Message-id: 1435311455-56048-1-git-send-email-kathy.wangting@huawei.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Ting Wang 2015-06-26 17:37:35 +08:00 committed by Stefan Hajnoczi
parent 25d9747b64
commit 970311646a
3 changed files with 22 additions and 8 deletions

View File

@ -708,6 +708,8 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
if (!s->dirty_bitmap) {
g_free(s->replaces);
block_job_release(bs);
return;
}
bdrv_set_enable_write_cache(s->target, true);

View File

@ -66,10 +66,7 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
block_job_set_speed(job, speed, &local_err);
if (local_err) {
bs->job = NULL;
bdrv_op_unblock_all(bs, job->blocker);
error_free(job->blocker);
g_free(job);
block_job_release(bs);
error_propagate(errp, local_err);
return NULL;
}
@ -77,16 +74,23 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
return job;
}
void block_job_release(BlockDriverState *bs)
{
BlockJob *job = bs->job;
bs->job = NULL;
bdrv_op_unblock_all(bs, job->blocker);
error_free(job->blocker);
g_free(job);
}
void block_job_completed(BlockJob *job, int ret)
{
BlockDriverState *bs = job->bs;
assert(bs->job == job);
job->cb(job->opaque, ret);
bs->job = NULL;
bdrv_op_unblock_all(bs, job->blocker);
error_free(job->blocker);
g_free(job);
block_job_release(bs);
}
void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)

View File

@ -165,6 +165,14 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns);
*/
void block_job_yield(BlockJob *job);
/**
* block_job_release:
* @bs: The block device.
*
* Release job resources when an error occurred or job completed.
*/
void block_job_release(BlockDriverState *bs);
/**
* block_job_completed:
* @job: The job being completed.