diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2017-05-08 16:13:03 +0200 |
---|---|---|
committer | Jeff Cody <jcody@redhat.com> | 2017-05-24 16:38:51 -0400 |
commit | f321dcb57f50be177250c7c5ba4b6334e9cb6ca5 (patch) | |
tree | a90002fe1312444a8122d5e38c61e45bb0c249f0 | |
parent | 05b0d8e3b8a1ed1a5840a317ce4f7f4ebe53156f (diff) |
blockjob: introduce block_job_pause/resume_all
Remove use of block_job_pause/resume from outside blockjob.c, thus
making them static. The new functions are used by the block layer,
so place them in blockjob_int.h.
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
Message-id: 20170508141310.8674-5-pbonzini@redhat.com
Signed-off-by: Jeff Cody <jcody@redhat.com>
-rw-r--r-- | block/io.c | 19 | ||||
-rw-r--r-- | blockjob.c | 114 | ||||
-rw-r--r-- | include/block/blockjob.h | 16 | ||||
-rw-r--r-- | include/block/blockjob_int.h | 14 |
4 files changed, 86 insertions, 77 deletions
diff --git a/block/io.c b/block/io.c index fdd7485c22..ed31810c0a 100644 --- a/block/io.c +++ b/block/io.c @@ -26,6 +26,7 @@ #include "trace.h" #include "sysemu/block-backend.h" #include "block/blockjob.h" +#include "block/blockjob_int.h" #include "block/block_int.h" #include "qemu/cutils.h" #include "qapi/error.h" @@ -301,16 +302,9 @@ void bdrv_drain_all_begin(void) bool waited = true; BlockDriverState *bs; BdrvNextIterator it; - BlockJob *job = NULL; GSList *aio_ctxs = NULL, *ctx; - while ((job = block_job_next(job))) { - AioContext *aio_context = blk_get_aio_context(job->blk); - - aio_context_acquire(aio_context); - block_job_pause(job); - aio_context_release(aio_context); - } + block_job_pause_all(); for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { AioContext *aio_context = bdrv_get_aio_context(bs); @@ -354,7 +348,6 @@ void bdrv_drain_all_end(void) { BlockDriverState *bs; BdrvNextIterator it; - BlockJob *job = NULL; for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { AioContext *aio_context = bdrv_get_aio_context(bs); @@ -365,13 +358,7 @@ void bdrv_drain_all_end(void) aio_context_release(aio_context); } - while ((job = block_job_next(job))) { - AioContext *aio_context = blk_get_aio_context(job->blk); - - aio_context_acquire(aio_context); - block_job_resume(job); - aio_context_release(aio_context); - } + block_job_resume_all(); } void bdrv_drain_all(void) diff --git a/blockjob.c b/blockjob.c index 5a722c3635..85ad610cae 100644 --- a/blockjob.c +++ b/blockjob.c @@ -55,36 +55,6 @@ struct BlockJobTxn { static QLIST_HEAD(, BlockJob) block_jobs = QLIST_HEAD_INITIALIZER(block_jobs); -static char *child_job_get_parent_desc(BdrvChild *c) -{ - BlockJob *job = c->opaque; - return g_strdup_printf("%s job '%s'", - BlockJobType_lookup[job->driver->job_type], - job->id); -} - -static const BdrvChildRole child_job = { - .get_parent_desc = child_job_get_parent_desc, - .stay_at_node = true, -}; - -static void block_job_drained_begin(void *opaque) -{ - BlockJob *job = opaque; - block_job_pause(job); -} - -static void block_job_drained_end(void *opaque) -{ - BlockJob *job = opaque; - block_job_resume(job); -} - -static const BlockDevOps block_job_dev_ops = { - .drained_begin = block_job_drained_begin, - .drained_end = block_job_drained_end, -}; - BlockJob *block_job_next(BlockJob *job) { if (!job) { @@ -106,6 +76,21 @@ BlockJob *block_job_get(const char *id) return NULL; } +static void block_job_pause(BlockJob *job) +{ + job->pause_count++; +} + +static void block_job_resume(BlockJob *job) +{ + assert(job->pause_count > 0); + job->pause_count--; + if (job->pause_count) { + return; + } + block_job_enter(job); +} + static void block_job_ref(BlockJob *job) { ++job->refcnt; @@ -171,6 +156,36 @@ static void block_job_detach_aio_context(void *opaque) block_job_unref(job); } +static char *child_job_get_parent_desc(BdrvChild *c) +{ + BlockJob *job = c->opaque; + return g_strdup_printf("%s job '%s'", + BlockJobType_lookup[job->driver->job_type], + job->id); +} + +static const BdrvChildRole child_job = { + .get_parent_desc = child_job_get_parent_desc, + .stay_at_node = true, +}; + +static void block_job_drained_begin(void *opaque) +{ + BlockJob *job = opaque; + block_job_pause(job); +} + +static void block_job_drained_end(void *opaque) +{ + BlockJob *job = opaque; + block_job_resume(job); +} + +static const BlockDevOps block_job_dev_ops = { + .drained_begin = block_job_drained_begin, + .drained_end = block_job_drained_end, +}; + void block_job_remove_all_bdrv(BlockJob *job) { GSList *l; @@ -471,11 +486,6 @@ void block_job_complete(BlockJob *job, Error **errp) job->driver->complete(job, errp); } -void block_job_pause(BlockJob *job) -{ - job->pause_count++; -} - void block_job_user_pause(BlockJob *job) { job->user_paused = true; @@ -520,16 +530,6 @@ void coroutine_fn block_job_pause_point(BlockJob *job) } } -void block_job_resume(BlockJob *job) -{ - assert(job->pause_count > 0); - job->pause_count--; - if (job->pause_count) { - return; - } - block_job_enter(job); -} - void block_job_user_resume(BlockJob *job) { if (job && job->user_paused && job->pause_count > 0) { @@ -723,6 +723,30 @@ static void block_job_event_completed(BlockJob *job, const char *msg) &error_abort); } +void block_job_pause_all(void) +{ + BlockJob *job = NULL; + while ((job = block_job_next(job))) { + AioContext *aio_context = blk_get_aio_context(job->blk); + + aio_context_acquire(aio_context); + block_job_pause(job); + aio_context_release(aio_context); + } +} + +void block_job_resume_all(void) +{ + BlockJob *job = NULL; + while ((job = block_job_next(job))) { + AioContext *aio_context = blk_get_aio_context(job->blk); + + aio_context_acquire(aio_context); + block_job_resume(job); + aio_context_release(aio_context); + } +} + void block_job_event_ready(BlockJob *job) { job->ready = true; diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 9e906f7d7e..09c7c694b5 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -235,14 +235,6 @@ void block_job_complete(BlockJob *job, Error **errp); BlockJobInfo *block_job_query(BlockJob *job, Error **errp); /** - * block_job_pause: - * @job: The job to be paused. - * - * Asynchronously pause the specified job. - */ -void block_job_pause(BlockJob *job); - -/** * block_job_user_pause: * @job: The job to be paused. * @@ -260,14 +252,6 @@ void block_job_user_pause(BlockJob *job); bool block_job_user_paused(BlockJob *job); /** - * block_job_resume: - * @job: The job to be resumed. - * - * Resume the specified job. Must be paired with a preceding block_job_pause. - */ -void block_job_resume(BlockJob *job); - -/** * block_job_user_resume: * @job: The job to be resumed. * diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 45cdfd4ac1..4f2d2ac75a 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -156,6 +156,20 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns); void block_job_yield(BlockJob *job); /** + * block_job_pause_all: + * + * Asynchronously pause all jobs. + */ +void block_job_pause_all(void); + +/** + * block_job_resume_all: + * + * Resume all block jobs. Must be paired with a preceding block_job_pause_all. + */ +void block_job_resume_all(void); + +/** * block_job_early_fail: * @bs: The block device. * |