From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 20/46] job: Add job_sleep_ns()
Date: Wed, 23 May 2018 15:11:29 +0200 [thread overview]
Message-ID: <20180523131155.12359-21-kwolf@redhat.com> (raw)
In-Reply-To: <20180523131155.12359-1-kwolf@redhat.com>
There is nothing block layer specific about block_job_sleep_ns(), so
move the function to Job.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
include/block/blockjob_int.h | 11 -----------
include/qemu/job.h | 19 ++++++++++++++++++-
block/backup.c | 2 +-
block/commit.c | 2 +-
block/mirror.c | 4 ++--
block/stream.c | 2 +-
blockjob.c | 27 ---------------------------
job.c | 32 ++++++++++++++++++++++++++++++++
tests/test-bdrv-drain.c | 8 ++++----
tests/test-blockjob-txn.c | 2 +-
tests/test-blockjob.c | 2 +-
11 files changed, 61 insertions(+), 50 deletions(-)
diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
index 0a614a89b8..8937f5b163 100644
--- a/include/block/blockjob_int.h
+++ b/include/block/blockjob_int.h
@@ -134,17 +134,6 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
void block_job_free(Job *job);
/**
- * block_job_sleep_ns:
- * @job: The job that calls the function.
- * @ns: How many nanoseconds to stop for.
- *
- * Put the job to sleep (assuming that it wasn't canceled) for @ns
- * %QEMU_CLOCK_REALTIME nanoseconds. Canceling the job will immediately
- * interrupt the wait.
- */
-void block_job_sleep_ns(BlockJob *job, int64_t ns);
-
-/**
* block_job_yield:
* @job: The job that calls the function.
*
diff --git a/include/qemu/job.h b/include/qemu/job.h
index 9dcff12283..509408f747 100644
--- a/include/qemu/job.h
+++ b/include/qemu/job.h
@@ -58,7 +58,7 @@ typedef struct Job {
Coroutine *co;
/**
- * Timer that is used by @block_job_sleep_ns. Accessed under job_mutex (in
+ * Timer that is used by @job_sleep_ns. Accessed under job_mutex (in
* job.c).
*/
QEMUTimer sleep_timer;
@@ -168,6 +168,13 @@ void job_enter_cond(Job *job, bool(*fn)(Job *job));
void job_start(Job *job);
/**
+ * @job: The job to enter.
+ *
+ * Continue the specified job by entering the coroutine.
+ */
+void job_enter(Job *job);
+
+/**
* @job: The job that is ready to pause.
*
* Pause now if job_pause() has been called. Jobs that perform lots of I/O
@@ -175,6 +182,16 @@ void job_start(Job *job);
*/
void coroutine_fn job_pause_point(Job *job);
+/**
+ * @job: The job that calls the function.
+ * @ns: How many nanoseconds to stop for.
+ *
+ * Put the job to sleep (assuming that it wasn't canceled) for @ns
+ * %QEMU_CLOCK_REALTIME nanoseconds. Canceling the job will immediately
+ * interrupt the wait.
+ */
+void coroutine_fn job_sleep_ns(Job *job, int64_t ns);
+
/** Returns the JobType of a given Job. */
JobType job_type(const Job *job);
diff --git a/block/backup.c b/block/backup.c
index 7d9aad9749..f3a4f7c898 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -338,7 +338,7 @@ static bool coroutine_fn yield_and_check(BackupBlockJob *job)
* return. Without a yield, the VM would not reboot. */
delay_ns = block_job_ratelimit_get_delay(&job->common, job->bytes_read);
job->bytes_read = 0;
- block_job_sleep_ns(&job->common, delay_ns);
+ job_sleep_ns(&job->common.job, delay_ns);
if (job_is_cancelled(&job->common.job)) {
return true;
diff --git a/block/commit.c b/block/commit.c
index 2fbc31077a..1c6cb6c298 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -172,7 +172,7 @@ static void coroutine_fn commit_run(void *opaque)
/* Note that even when no rate limit is applied we need to yield
* with no pending I/O here so that bdrv_drain_all() returns.
*/
- block_job_sleep_ns(&s->common, delay_ns);
+ job_sleep_ns(&s->common.job, delay_ns);
if (job_is_cancelled(&s->common.job)) {
break;
}
diff --git a/block/mirror.c b/block/mirror.c
index 95fc8072b0..5d8f75c677 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -595,7 +595,7 @@ static void mirror_throttle(MirrorBlockJob *s)
if (now - s->last_pause_ns > BLOCK_JOB_SLICE_TIME) {
s->last_pause_ns = now;
- block_job_sleep_ns(&s->common, 0);
+ job_sleep_ns(&s->common.job, 0);
} else {
job_pause_point(&s->common.job);
}
@@ -869,7 +869,7 @@ static void coroutine_fn mirror_run(void *opaque)
cnt == 0 ? BLOCK_JOB_SLICE_TIME : 0);
}
trace_mirror_before_sleep(s, cnt, s->synced, delay_ns);
- block_job_sleep_ns(&s->common, delay_ns);
+ job_sleep_ns(&s->common.job, delay_ns);
if (job_is_cancelled(&s->common.job) &&
(!s->synced || s->common.force))
{
diff --git a/block/stream.c b/block/stream.c
index 6d8b7b6eee..1faab02086 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -140,7 +140,7 @@ static void coroutine_fn stream_run(void *opaque)
/* Note that even when no rate limit is applied we need to yield
* with no pending I/O here so that bdrv_drain_all() returns.
*/
- block_job_sleep_ns(&s->common, delay_ns);
+ job_sleep_ns(&s->common.job, delay_ns);
if (job_is_cancelled(&s->common.job)) {
break;
}
diff --git a/blockjob.c b/blockjob.c
index 313b1ff7ce..4dc360c794 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -181,7 +181,6 @@ void block_job_free(Job *job)
block_job_detach_aio_context, bjob);
blk_unref(bjob->blk);
error_free(bjob->blocker);
- assert(!timer_pending(&bjob->job.sleep_timer));
}
static void block_job_attached_aio_context(AioContext *new_context,
@@ -290,13 +289,6 @@ const BlockJobDriver *block_job_driver(BlockJob *job)
return job->driver;
}
-static void block_job_sleep_timer_cb(void *opaque)
-{
- BlockJob *job = opaque;
-
- block_job_enter(job);
-}
-
static void block_job_decommission(BlockJob *job)
{
assert(job);
@@ -866,9 +858,6 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
job->opaque = opaque;
job->auto_finalize = !(flags & BLOCK_JOB_MANUAL_FINALIZE);
job->auto_dismiss = !(flags & BLOCK_JOB_MANUAL_DISMISS);
- aio_timer_init(qemu_get_aio_context(), &job->job.sleep_timer,
- QEMU_CLOCK_REALTIME, SCALE_NS,
- block_job_sleep_timer_cb, job);
error_setg(&job->blocker, "block device is in use by block job: %s",
job_type_str(&job->job));
@@ -931,22 +920,6 @@ void block_job_enter(BlockJob *job)
job_enter_cond(&job->job, NULL);
}
-void block_job_sleep_ns(BlockJob *job, int64_t ns)
-{
- assert(job->job.busy);
-
- /* Check cancellation *before* setting busy = false, too! */
- if (job_is_cancelled(&job->job)) {
- return;
- }
-
- if (!job_should_pause(&job->job)) {
- job_do_yield(&job->job, qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + ns);
- }
-
- job_pause_point(&job->job);
-}
-
void block_job_yield(BlockJob *job)
{
assert(job->job.busy);
diff --git a/job.c b/job.c
index 78497fd6f5..1b8cba15ff 100644
--- a/job.c
+++ b/job.c
@@ -152,6 +152,13 @@ Job *job_get(const char *id)
return NULL;
}
+static void job_sleep_timer_cb(void *opaque)
+{
+ Job *job = opaque;
+
+ job_enter(job);
+}
+
void *job_create(const char *job_id, const JobDriver *driver, AioContext *ctx,
Error **errp)
{
@@ -178,6 +185,9 @@ void *job_create(const char *job_id, const JobDriver *driver, AioContext *ctx,
job->pause_count = 1;
job_state_transition(job, JOB_STATUS_CREATED);
+ aio_timer_init(qemu_get_aio_context(), &job->sleep_timer,
+ QEMU_CLOCK_REALTIME, SCALE_NS,
+ job_sleep_timer_cb, job);
QLIST_INSERT_HEAD(&jobs, job, job_list);
@@ -193,6 +203,7 @@ void job_unref(Job *job)
{
if (--job->refcnt == 0) {
assert(job->status == JOB_STATUS_NULL);
+ assert(!timer_pending(&job->sleep_timer));
if (job->driver->free) {
job->driver->free(job);
@@ -232,6 +243,11 @@ void job_enter_cond(Job *job, bool(*fn)(Job *job))
aio_co_wake(job->co);
}
+void job_enter(Job *job)
+{
+ job_enter_cond(job, NULL);
+}
+
/* Yield, and schedule a timer to reenter the coroutine after @ns nanoseconds.
* Reentering the job coroutine with block_job_enter() before the timer has
* expired is allowed and cancels the timer.
@@ -283,6 +299,22 @@ void coroutine_fn job_pause_point(Job *job)
}
}
+void coroutine_fn job_sleep_ns(Job *job, int64_t ns)
+{
+ assert(job->busy);
+
+ /* Check cancellation *before* setting busy = false, too! */
+ if (job_is_cancelled(job)) {
+ return;
+ }
+
+ if (!job_should_pause(job)) {
+ job_do_yield(job, qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + ns);
+ }
+
+ job_pause_point(job);
+}
+
/**
* All jobs must allow a pause point before entering their job proper. This
* ensures that jobs can be paused prior to being started, then resumed later.
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
index c9f2f9b183..50232f5eaf 100644
--- a/tests/test-bdrv-drain.c
+++ b/tests/test-bdrv-drain.c
@@ -508,7 +508,7 @@ static void coroutine_fn test_job_start(void *opaque)
block_job_event_ready(&s->common);
while (!s->should_complete) {
- block_job_sleep_ns(&s->common, 100000);
+ job_sleep_ns(&s->common.job, 100000);
}
job_defer_to_main_loop(&s->common.job, test_job_completed, NULL);
@@ -553,7 +553,7 @@ static void test_blockjob_common(enum drain_type drain_type)
g_assert_cmpint(job->job.pause_count, ==, 0);
g_assert_false(job->job.paused);
- g_assert_false(job->job.busy); /* We're in block_job_sleep_ns() */
+ g_assert_false(job->job.busy); /* We're in job_sleep_ns() */
do_drain_begin(drain_type, src);
@@ -571,7 +571,7 @@ static void test_blockjob_common(enum drain_type drain_type)
g_assert_cmpint(job->job.pause_count, ==, 0);
g_assert_false(job->job.paused);
- g_assert_false(job->job.busy); /* We're in block_job_sleep_ns() */
+ g_assert_false(job->job.busy); /* We're in job_sleep_ns() */
do_drain_begin(drain_type, target);
@@ -589,7 +589,7 @@ static void test_blockjob_common(enum drain_type drain_type)
g_assert_cmpint(job->job.pause_count, ==, 0);
g_assert_false(job->job.paused);
- g_assert_false(job->job.busy); /* We're in block_job_sleep_ns() */
+ g_assert_false(job->job.busy); /* We're in job_sleep_ns() */
ret = block_job_complete_sync(job, &error_abort);
g_assert_cmpint(ret, ==, 0);
diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c
index 323e154a00..0e6162bc71 100644
--- a/tests/test-blockjob-txn.c
+++ b/tests/test-blockjob-txn.c
@@ -45,7 +45,7 @@ static void coroutine_fn test_block_job_run(void *opaque)
while (s->iterations--) {
if (s->use_timer) {
- block_job_sleep_ns(job, 0);
+ job_sleep_ns(&job->job, 0);
} else {
block_job_yield(job);
}
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
index 1d18325feb..b329bd5274 100644
--- a/tests/test-blockjob.c
+++ b/tests/test-blockjob.c
@@ -188,7 +188,7 @@ static void coroutine_fn cancel_job_start(void *opaque)
block_job_event_ready(&s->common);
}
- block_job_sleep_ns(&s->common, 100000);
+ job_sleep_ns(&s->common.job, 100000);
}
defer:
--
2.13.6
next prev parent reply other threads:[~2018-05-23 13:12 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-23 13:11 [Qemu-devel] [PULL 00/46] Block layer patches Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 01/46] qemu-iotests: Fix paths for NFS Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 02/46] qemu-iotests: Filter NFS paths Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 03/46] qemu-iotests: 086 doesn't work with NFS Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 04/46] sheepdog: Remove unnecessary NULL check in sd_prealloc() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 05/46] qemu-iotests: Add more tests to "migration" group Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 06/46] qemu-iotests: Remove MIG_SOCKET from non-migration tests Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 07/46] blockjob: Update block-job-pause/resume documentation Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 08/46] blockjob: Improve BlockJobInfo.offset/len documentation Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 09/46] job: Create Job, JobDriver and job_create() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 10/46] job: Rename BlockJobType into JobType Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 11/46] job: Add JobDriver.job_type Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 12/46] job: Add job_delete() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 13/46] job: Maintain a list of all jobs Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 14/46] job: Move state transitions to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 15/46] job: Add reference counting Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 16/46] job: Move cancelled to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 17/46] job: Add Job.aio_context Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 18/46] job: Move defer_to_main_loop to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 19/46] job: Move coroutine and related code " Kevin Wolf
2018-05-23 13:11 ` Kevin Wolf [this message]
2018-05-23 13:11 ` [Qemu-devel] [PULL 21/46] job: Move pause/resume functions " Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 22/46] job: Replace BlockJob.completed with job_is_completed() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 23/46] job: Move BlockJobCreateFlags to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 24/46] blockjob: Split block_job_event_pending() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 25/46] job: Add job_event_*() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 26/46] job: Move single job finalisation to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 27/46] job: Convert block_job_cancel_async() " Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 28/46] job: Add job_drain() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 29/46] job: Move .complete callback to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 30/46] job: Move job_finish_sync() " Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 31/46] job: Switch transactions to JobTxn Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 32/46] job: Move transactions to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 33/46] job: Move completion and cancellation " Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 34/46] block: Cancel job in bdrv_close_all() callers Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 35/46] job: Add job_yield() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 36/46] job: Add job_dismiss() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 37/46] job: Add job_is_ready() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 38/46] job: Add job_transition_to_ready() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 39/46] job: Move progress fields to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 40/46] job: Introduce qapi/job.json Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 41/46] job: Add JOB_STATUS_CHANGE QMP event Kevin Wolf
2018-05-23 19:50 ` Eric Blake
2018-05-23 13:11 ` [Qemu-devel] [PULL 42/46] job: Add lifecycle QMP commands Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 43/46] job: Add query-jobs QMP command Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 44/46] blockjob: Remove BlockJob.driver Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 45/46] iotests: Move qmp_to_opts() to VM Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 46/46] qemu-iotests: Test job-* with block jobs Kevin Wolf
2018-05-23 14:02 ` [Qemu-devel] [PULL 00/46] Block layer patches no-reply
2018-05-24 13:21 ` Peter Maydell
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=20180523131155.12359-21-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.