[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 2/5] blockjob: add block_job_start
From: |
John Snow |
Subject: |
[Qemu-block] [PATCH 2/5] blockjob: add block_job_start |
Date: |
Mon, 8 Aug 2016 15:09:38 -0400 |
Instead of automatically starting jobs at creation time via backup_start
et al, we'd like to return a job object pointer that can be started
manually at later point in time.
For now, add the block_job_start mechanism and start the jobs
automatically as we have been doing, with conversions job-by-job coming
in later patches.
Signed-off-by: John Snow <address@hidden>
---
block/backup.c | 2 +-
block/commit.c | 2 +-
block/mirror.c | 2 +-
block/stream.c | 2 +-
blockjob.c | 11 ++++++++++-
include/block/blockjob.h | 8 ++++++++
tests/test-blockjob-txn.c | 2 +-
7 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/block/backup.c b/block/backup.c
index 2c05323..2229e26 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -578,7 +578,7 @@ void backup_start(const char *job_id, BlockDriverState *bs,
job->common.len = len;
job->common.co = qemu_coroutine_create(backup_run, job);
block_job_txn_add_job(txn, &job->common);
- qemu_coroutine_enter(job->common.co);
+ block_job_start(&job->common);
return;
error:
diff --git a/block/commit.c b/block/commit.c
index 553e18d..f93864a 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -278,7 +278,7 @@ void commit_start(const char *job_id, BlockDriverState *bs,
s->common.co = qemu_coroutine_create(commit_run, s);
trace_commit_start(bs, base, top, s, s->common.co, opaque);
- qemu_coroutine_enter(s->common.co);
+ block_job_start(&s->common);
}
diff --git a/block/mirror.c b/block/mirror.c
index e0b3f41..79d9b84 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -965,7 +965,7 @@ static void mirror_start_job(const char *job_id,
BlockDriverState *bs,
s->common.co = qemu_coroutine_create(mirror_run, s);
trace_mirror_start(bs, s, s->common.co, opaque);
- qemu_coroutine_enter(s->common.co);
+ block_job_start(&s->common);
}
void mirror_start(const char *job_id, BlockDriverState *bs,
diff --git a/block/stream.c b/block/stream.c
index 3187481..c2a8a3e 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -233,5 +233,5 @@ void stream_start(const char *job_id, BlockDriverState *bs,
s->on_error = on_error;
s->common.co = qemu_coroutine_create(stream_run, s);
trace_stream_start(bs, base, s, s->common.co, opaque);
- qemu_coroutine_enter(s->common.co);
+ block_job_start(&s->common);
}
diff --git a/blockjob.c b/blockjob.c
index e045091..0d07abc 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -158,7 +158,8 @@ void *block_job_create(const char *job_id, const
BlockJobDriver *driver,
job->blk = blk;
job->cb = cb;
job->opaque = opaque;
- job->busy = true;
+ job->busy = false;
+ job->paused = true;
job->refcnt = 1;
bs->job = job;
@@ -181,6 +182,14 @@ void *block_job_create(const char *job_id, const
BlockJobDriver *driver,
return job;
}
+void block_job_start(BlockJob *job)
+{
+ assert(job && job->co && job->paused && !job->busy);
+ job->paused = false;
+ job->busy = true;
+ qemu_coroutine_enter(job->co);
+}
+
void block_job_ref(BlockJob *job)
{
++job->refcnt;
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index 4ddb4ae..e06258f 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -246,6 +246,14 @@ void *block_job_create(const char *job_id, const
BlockJobDriver *driver,
BlockCompletionFunc *cb, void *opaque, Error **errp);
/**
+ * block_job_start:
+ * @job: The job object as returned by @block_job_create.
+ *
+ * Begins execution of a block job.
+ */
+void block_job_start(BlockJob *job);
+
+/**
* block_job_sleep_ns:
* @job: The job that calls the function.
* @clock: The clock to sleep on.
diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c
index d049cba..8399f62 100644
--- a/tests/test-blockjob-txn.c
+++ b/tests/test-blockjob-txn.c
@@ -106,7 +106,7 @@ static BlockJob *test_block_job_start(unsigned int
iterations,
s->common.co = qemu_coroutine_create(test_block_job_run, s);
data->job = s;
data->result = result;
- qemu_coroutine_enter(s->common.co);
+ block_job_start(&s->common);
return &s->common;
}
--
2.7.4
- [Qemu-block] [PATCH 0/5] blockjobs: Fix transactional race condition, John Snow, 2016/08/08
- [Qemu-block] [PATCH 1/5] blockjob: fix dead pointer in txn list, John Snow, 2016/08/08
- [Qemu-block] [PATCH 2/5] blockjob: add block_job_start,
John Snow <=
- [Qemu-block] [PATCH 4/5] blockjob: add .clean property, John Snow, 2016/08/08
- [Qemu-block] [PATCH 5/5] iotests: add transactional failure race test, John Snow, 2016/08/08
- [Qemu-block] [PATCH 3/5] blockjob: refactor backup_start as backup_job_create, John Snow, 2016/08/08
- Re: [Qemu-block] [Qemu-devel] [PATCH 0/5] blockjobs: Fix transactional race condition, no-reply, 2016/08/08
- Re: [Qemu-block] [PATCH 0/5] blockjobs: Fix transactional race condition, John Snow, 2016/08/08