qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, jcody@redhat.com, vsementsov@virtuozzo.com,
	famz@redhat.com, qemu-devel@nongnu.org,
	John Snow <jsnow@redhat.com>
Subject: [Qemu-devel] [PATCH 2/5] blockjob: add block_job_start
Date: Mon,  8 Aug 2016 15:09:38 -0400	[thread overview]
Message-ID: <1470683381-16680-3-git-send-email-jsnow@redhat.com> (raw)
In-Reply-To: <1470683381-16680-1-git-send-email-jsnow@redhat.com>

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 <jsnow@redhat.com>
---
 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

  parent reply	other threads:[~2016-08-08 19:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-08 19:09 [Qemu-devel] [PATCH 0/5] blockjobs: Fix transactional race condition John Snow
2016-08-08 19:09 ` [Qemu-devel] [PATCH 1/5] blockjob: fix dead pointer in txn list John Snow
2016-09-29 18:16   ` Eric Blake
2016-08-08 19:09 ` John Snow [this message]
2016-08-08 19:09 ` [Qemu-devel] [PATCH 3/5] blockjob: refactor backup_start as backup_job_create John Snow
2016-08-08 21:23   ` John Snow
2016-08-08 19:09 ` [Qemu-devel] [PATCH 4/5] blockjob: add .clean property John Snow
2016-08-08 19:09 ` [Qemu-devel] [PATCH 5/5] iotests: add transactional failure race test John Snow
2016-08-10 15:19   ` Vladimir Sementsov-Ogievskiy
2016-08-08 19:18 ` [Qemu-devel] [PATCH 0/5] blockjobs: Fix transactional race condition no-reply
2016-08-08 19:19 ` John Snow
     [not found] ` <57E94491.8090501@virtuozzo.com>
     [not found]   ` <bf412a34-acb7-d3df-1710-ee7917ee2060@redhat.com>
2016-09-28 12:16     ` Vladimir Sementsov-Ogievskiy
2016-09-29 11:33       ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2016-09-29 12:30         ` Stefan Hajnoczi
2016-09-29 20:58         ` John Snow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1470683381-16680-3-git-send-email-jsnow@redhat.com \
    --to=jsnow@redhat.com \
    --cc=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).