block: return error-code from bdrv_invalidate_cache
This is the only coroutine wrapper from block.c and block/io.c which doesn't return a value, so let's convert it to the common behavior, to simplify moving to generated coroutine wrappers in a further commit. Also, bdrv_invalidate_cache is a void function, returning error only through **errp parameter, which is considered to be bad practice, as it forces callers to define and propagate local_err variable, so conversion is good anyway. This patch leaves the conversion of .bdrv_co_invalidate_cache() driver callbacks and bdrv_invalidate_cache_all() for another day. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20200924185414.28642-2-vsementsov@virtuozzo.com>
This commit is contained in:
parent
eefffb0244
commit
5416645fcf
30
block.c
30
block.c
@ -5781,7 +5781,7 @@ void bdrv_init_with_whitelist(void)
|
|||||||
bdrv_init();
|
bdrv_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
|
static int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
BdrvChild *child, *parent;
|
BdrvChild *child, *parent;
|
||||||
@ -5791,14 +5791,14 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
|
|||||||
BdrvDirtyBitmap *bm;
|
BdrvDirtyBitmap *bm;
|
||||||
|
|
||||||
if (!bs->drv) {
|
if (!bs->drv) {
|
||||||
return;
|
return -ENOMEDIUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLIST_FOREACH(child, &bs->children, next) {
|
QLIST_FOREACH(child, &bs->children, next) {
|
||||||
bdrv_co_invalidate_cache(child->bs, &local_err);
|
bdrv_co_invalidate_cache(child->bs, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5821,7 +5821,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
|
|||||||
ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, errp);
|
ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, errp);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
bs->open_flags |= BDRV_O_INACTIVE;
|
bs->open_flags |= BDRV_O_INACTIVE;
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
bdrv_set_perm(bs, perm, shared_perm);
|
bdrv_set_perm(bs, perm, shared_perm);
|
||||||
|
|
||||||
@ -5830,7 +5830,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
|
|||||||
if (local_err) {
|
if (local_err) {
|
||||||
bs->open_flags |= BDRV_O_INACTIVE;
|
bs->open_flags |= BDRV_O_INACTIVE;
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5842,7 +5842,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
bs->open_flags |= BDRV_O_INACTIVE;
|
bs->open_flags |= BDRV_O_INACTIVE;
|
||||||
error_setg_errno(errp, -ret, "Could not refresh total sector count");
|
error_setg_errno(errp, -ret, "Could not refresh total sector count");
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5852,27 +5852,30 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
|
|||||||
if (local_err) {
|
if (local_err) {
|
||||||
bs->open_flags |= BDRV_O_INACTIVE;
|
bs->open_flags |= BDRV_O_INACTIVE;
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct InvalidateCacheCo {
|
typedef struct InvalidateCacheCo {
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
Error **errp;
|
Error **errp;
|
||||||
bool done;
|
bool done;
|
||||||
|
int ret;
|
||||||
} InvalidateCacheCo;
|
} InvalidateCacheCo;
|
||||||
|
|
||||||
static void coroutine_fn bdrv_invalidate_cache_co_entry(void *opaque)
|
static void coroutine_fn bdrv_invalidate_cache_co_entry(void *opaque)
|
||||||
{
|
{
|
||||||
InvalidateCacheCo *ico = opaque;
|
InvalidateCacheCo *ico = opaque;
|
||||||
bdrv_co_invalidate_cache(ico->bs, ico->errp);
|
ico->ret = bdrv_co_invalidate_cache(ico->bs, ico->errp);
|
||||||
ico->done = true;
|
ico->done = true;
|
||||||
aio_wait_kick();
|
aio_wait_kick();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
|
int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
|
||||||
{
|
{
|
||||||
Coroutine *co;
|
Coroutine *co;
|
||||||
InvalidateCacheCo ico = {
|
InvalidateCacheCo ico = {
|
||||||
@ -5889,22 +5892,23 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
|
|||||||
bdrv_coroutine_enter(bs, co);
|
bdrv_coroutine_enter(bs, co);
|
||||||
BDRV_POLL_WHILE(bs, !ico.done);
|
BDRV_POLL_WHILE(bs, !ico.done);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ico.ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bdrv_invalidate_cache_all(Error **errp)
|
void bdrv_invalidate_cache_all(Error **errp)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
Error *local_err = NULL;
|
|
||||||
BdrvNextIterator it;
|
BdrvNextIterator it;
|
||||||
|
|
||||||
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);
|
||||||
|
int ret;
|
||||||
|
|
||||||
aio_context_acquire(aio_context);
|
aio_context_acquire(aio_context);
|
||||||
bdrv_invalidate_cache(bs, &local_err);
|
ret = bdrv_invalidate_cache(bs, errp);
|
||||||
aio_context_release(aio_context);
|
aio_context_release(aio_context);
|
||||||
if (local_err) {
|
if (ret < 0) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
bdrv_next_cleanup(&it);
|
bdrv_next_cleanup(&it);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -460,7 +460,7 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb);
|
|||||||
int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);
|
int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);
|
||||||
|
|
||||||
/* Invalidate any cached metadata used by image formats */
|
/* Invalidate any cached metadata used by image formats */
|
||||||
void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
|
int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
|
||||||
void bdrv_invalidate_cache_all(Error **errp);
|
void bdrv_invalidate_cache_all(Error **errp);
|
||||||
int bdrv_inactivate_all(void);
|
int bdrv_inactivate_all(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user