mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 23:03:54 -06:00
block: convert bdrv_check callback to coroutine_fn
Suggested-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <1516279431-30424-8-git-send-email-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
2b148f392b
commit
2fd6163884
10 changed files with 103 additions and 45 deletions
43
block.c
43
block.c
|
@ -3455,17 +3455,54 @@ static void bdrv_delete(BlockDriverState *bs)
|
|||
* free of errors) or -errno when an internal error occurred. The results of the
|
||||
* check are stored in res.
|
||||
*/
|
||||
int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix)
|
||||
static int coroutine_fn bdrv_co_check(BlockDriverState *bs,
|
||||
BdrvCheckResult *res, BdrvCheckMode fix)
|
||||
{
|
||||
if (bs->drv == NULL) {
|
||||
return -ENOMEDIUM;
|
||||
}
|
||||
if (bs->drv->bdrv_check == NULL) {
|
||||
if (bs->drv->bdrv_co_check == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
memset(res, 0, sizeof(*res));
|
||||
return bs->drv->bdrv_check(bs, res, fix);
|
||||
return bs->drv->bdrv_co_check(bs, res, fix);
|
||||
}
|
||||
|
||||
typedef struct CheckCo {
|
||||
BlockDriverState *bs;
|
||||
BdrvCheckResult *res;
|
||||
BdrvCheckMode fix;
|
||||
int ret;
|
||||
} CheckCo;
|
||||
|
||||
static void bdrv_check_co_entry(void *opaque)
|
||||
{
|
||||
CheckCo *cco = opaque;
|
||||
cco->ret = bdrv_co_check(cco->bs, cco->res, cco->fix);
|
||||
}
|
||||
|
||||
int bdrv_check(BlockDriverState *bs,
|
||||
BdrvCheckResult *res, BdrvCheckMode fix)
|
||||
{
|
||||
Coroutine *co;
|
||||
CheckCo cco = {
|
||||
.bs = bs,
|
||||
.res = res,
|
||||
.ret = -EINPROGRESS,
|
||||
.fix = fix,
|
||||
};
|
||||
|
||||
if (qemu_in_coroutine()) {
|
||||
/* Fast-path if already in coroutine context */
|
||||
bdrv_check_co_entry(&cco);
|
||||
} else {
|
||||
co = qemu_coroutine_create(bdrv_check_co_entry, &cco);
|
||||
qemu_coroutine_enter(co);
|
||||
BDRV_POLL_WHILE(bs, cco.ret == -EINPROGRESS);
|
||||
}
|
||||
|
||||
return cco.ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue