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>
This commit is contained in:
Paolo Bonzini 2017-05-08 16:13:03 +02:00 committed by Jeff Cody
parent 05b0d8e3b8
commit f321dcb57f
4 changed files with 86 additions and 77 deletions

View File

@ -26,6 +26,7 @@
#include "trace.h" #include "trace.h"
#include "sysemu/block-backend.h" #include "sysemu/block-backend.h"
#include "block/blockjob.h" #include "block/blockjob.h"
#include "block/blockjob_int.h"
#include "block/block_int.h" #include "block/block_int.h"
#include "qemu/cutils.h" #include "qemu/cutils.h"
#include "qapi/error.h" #include "qapi/error.h"
@ -301,16 +302,9 @@ void bdrv_drain_all_begin(void)
bool waited = true; bool waited = true;
BlockDriverState *bs; BlockDriverState *bs;
BdrvNextIterator it; BdrvNextIterator it;
BlockJob *job = NULL;
GSList *aio_ctxs = NULL, *ctx; GSList *aio_ctxs = NULL, *ctx;
while ((job = block_job_next(job))) { block_job_pause_all();
AioContext *aio_context = blk_get_aio_context(job->blk);
aio_context_acquire(aio_context);
block_job_pause(job);
aio_context_release(aio_context);
}
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
AioContext *aio_context = bdrv_get_aio_context(bs); AioContext *aio_context = bdrv_get_aio_context(bs);
@ -354,7 +348,6 @@ void bdrv_drain_all_end(void)
{ {
BlockDriverState *bs; BlockDriverState *bs;
BdrvNextIterator it; BdrvNextIterator it;
BlockJob *job = NULL;
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
AioContext *aio_context = bdrv_get_aio_context(bs); AioContext *aio_context = bdrv_get_aio_context(bs);
@ -365,13 +358,7 @@ void bdrv_drain_all_end(void)
aio_context_release(aio_context); aio_context_release(aio_context);
} }
while ((job = block_job_next(job))) { block_job_resume_all();
AioContext *aio_context = blk_get_aio_context(job->blk);
aio_context_acquire(aio_context);
block_job_resume(job);
aio_context_release(aio_context);
}
} }
void bdrv_drain_all(void) void bdrv_drain_all(void)

View File

@ -55,36 +55,6 @@ struct BlockJobTxn {
static QLIST_HEAD(, BlockJob) block_jobs = QLIST_HEAD_INITIALIZER(block_jobs); 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) BlockJob *block_job_next(BlockJob *job)
{ {
if (!job) { if (!job) {
@ -106,6 +76,21 @@ BlockJob *block_job_get(const char *id)
return NULL; 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) static void block_job_ref(BlockJob *job)
{ {
++job->refcnt; ++job->refcnt;
@ -171,6 +156,36 @@ static void block_job_detach_aio_context(void *opaque)
block_job_unref(job); 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) void block_job_remove_all_bdrv(BlockJob *job)
{ {
GSList *l; GSList *l;
@ -471,11 +486,6 @@ void block_job_complete(BlockJob *job, Error **errp)
job->driver->complete(job, errp); job->driver->complete(job, errp);
} }
void block_job_pause(BlockJob *job)
{
job->pause_count++;
}
void block_job_user_pause(BlockJob *job) void block_job_user_pause(BlockJob *job)
{ {
job->user_paused = true; 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) void block_job_user_resume(BlockJob *job)
{ {
if (job && job->user_paused && job->pause_count > 0) { 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); &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) void block_job_event_ready(BlockJob *job)
{ {
job->ready = true; job->ready = true;

View File

@ -234,14 +234,6 @@ void block_job_complete(BlockJob *job, Error **errp);
*/ */
BlockJobInfo *block_job_query(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: * block_job_user_pause:
* @job: The job to be paused. * @job: The job to be paused.
@ -259,14 +251,6 @@ void block_job_user_pause(BlockJob *job);
*/ */
bool block_job_user_paused(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: * block_job_user_resume:
* @job: The job to be resumed. * @job: The job to be resumed.

View File

@ -155,6 +155,20 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns);
*/ */
void block_job_yield(BlockJob *job); 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: * block_job_early_fail:
* @bs: The block device. * @bs: The block device.