blockjob: Simplify block_job_finish_sync
With job->completed and job->ret to replace BlockFinishData. Signed-off-by: Fam Zheng <famz@redhat.com> Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 1446765200-3054-9-git-send-email-jsnow@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
a689dbf2df
commit
94db6d2d30
28
blockjob.c
28
blockjob.c
@ -188,43 +188,29 @@ struct BlockFinishData {
|
|||||||
int ret;
|
int ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void block_job_finish_cb(void *opaque, int ret)
|
|
||||||
{
|
|
||||||
struct BlockFinishData *data = opaque;
|
|
||||||
|
|
||||||
data->cancelled = block_job_is_cancelled(data->job);
|
|
||||||
data->ret = ret;
|
|
||||||
data->cb(data->opaque, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int block_job_finish_sync(BlockJob *job,
|
static int block_job_finish_sync(BlockJob *job,
|
||||||
void (*finish)(BlockJob *, Error **errp),
|
void (*finish)(BlockJob *, Error **errp),
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
struct BlockFinishData data;
|
|
||||||
BlockDriverState *bs = job->bs;
|
BlockDriverState *bs = job->bs;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
|
int ret;
|
||||||
|
|
||||||
assert(bs->job == job);
|
assert(bs->job == job);
|
||||||
|
|
||||||
/* Set up our own callback to store the result and chain to
|
block_job_ref(job);
|
||||||
* the original callback.
|
|
||||||
*/
|
|
||||||
data.job = job;
|
|
||||||
data.cb = job->cb;
|
|
||||||
data.opaque = job->opaque;
|
|
||||||
data.ret = -EINPROGRESS;
|
|
||||||
job->cb = block_job_finish_cb;
|
|
||||||
job->opaque = &data;
|
|
||||||
finish(job, &local_err);
|
finish(job, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
|
block_job_unref(job);
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
while (data.ret == -EINPROGRESS) {
|
while (!job->completed) {
|
||||||
aio_poll(bdrv_get_aio_context(bs), true);
|
aio_poll(bdrv_get_aio_context(bs), true);
|
||||||
}
|
}
|
||||||
return (data.cancelled && data.ret == 0) ? -ECANCELED : data.ret;
|
ret = (job->cancelled && job->ret == 0) ? -ECANCELED : job->ret;
|
||||||
|
block_job_unref(job);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A wrapper around block_job_cancel() taking an Error ** parameter so it may be
|
/* A wrapper around block_job_cancel() taking an Error ** parameter so it may be
|
||||||
|
Loading…
Reference in New Issue
Block a user