From 80fa2c756b3241f24015a7503a01f7999d4a942d Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Fri, 13 Apr 2018 18:50:05 +0200 Subject: job: Add reference counting This moves reference counting from BlockJob to Job. In order to keep calling the BlockJob cleanup code when the job is deleted via job_unref(), introduce a new JobDriver.free callback. Every block job must use block_job_free() for this callback, this is asserted in block_job_create(). Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: John Snow --- tests/test-bdrv-drain.c | 1 + tests/test-blockjob-txn.c | 1 + tests/test-blockjob.c | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index fe9f412b39..f9e37d479c 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -522,6 +522,7 @@ static void test_job_complete(BlockJob *job, Error **errp) BlockJobDriver test_job_driver = { .job_driver = { .instance_size = sizeof(TestBlockJob), + .free = block_job_free, }, .start = test_job_start, .complete = test_job_complete, diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c index 48b12d1744..b49b28ca27 100644 --- a/tests/test-blockjob-txn.c +++ b/tests/test-blockjob-txn.c @@ -76,6 +76,7 @@ static void test_block_job_cb(void *opaque, int ret) static const BlockJobDriver test_block_job_driver = { .job_driver = { .instance_size = sizeof(TestBlockJob), + .free = block_job_free, }, .start = test_block_job_run, }; diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 6ccd585dee..e24fc3f140 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -19,6 +19,7 @@ static const BlockJobDriver test_block_job_driver = { .job_driver = { .instance_size = sizeof(BlockJob), + .free = block_job_free, }, }; @@ -196,6 +197,7 @@ static void coroutine_fn cancel_job_start(void *opaque) static const BlockJobDriver test_cancel_driver = { .job_driver = { .instance_size = sizeof(CancelJob), + .free = block_job_free, }, .start = cancel_job_start, .complete = cancel_job_complete, @@ -210,7 +212,7 @@ static CancelJob *create_common(BlockJob **pjob) blk = create_blk(NULL); job = mk_job(blk, "Steve", &test_cancel_driver, true, BLOCK_JOB_MANUAL_FINALIZE | BLOCK_JOB_MANUAL_DISMISS); - block_job_ref(job); + job_ref(&job->job); assert(job->job.status == JOB_STATUS_CREATED); s = container_of(job, CancelJob, common); s->blk = blk; @@ -231,7 +233,7 @@ static void cancel_common(CancelJob *s) block_job_dismiss(&dummy, &error_abort); } assert(job->job.status == JOB_STATUS_NULL); - block_job_unref(job); + job_unref(&job->job); destroy_blk(blk); } -- cgit v1.2.3