mirror of https://github.com/xemu-project/xemu.git
block/io: refactor save/load vmstate
Like for read/write in a previous commit, drop extra indirection layer, generate directly bdrv_readv_vmstate() and bdrv_writev_vmstate(). 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: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20200924185414.28642-8-vsementsov@virtuozzo.com>
This commit is contained in:
parent
fae2681add
commit
b33b354f3a
|
@ -57,11 +57,9 @@ bdrv_common_block_status_above(BlockDriverState *bs,
|
||||||
int64_t *map,
|
int64_t *map,
|
||||||
BlockDriverState **file);
|
BlockDriverState **file);
|
||||||
|
|
||||||
int coroutine_fn
|
int coroutine_fn bdrv_co_readv_vmstate(BlockDriverState *bs,
|
||||||
bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
|
QEMUIOVector *qiov, int64_t pos);
|
||||||
bool is_read);
|
int coroutine_fn bdrv_co_writev_vmstate(BlockDriverState *bs,
|
||||||
int generated_co_wrapper
|
QEMUIOVector *qiov, int64_t pos);
|
||||||
bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
|
|
||||||
bool is_read);
|
|
||||||
|
|
||||||
#endif /* BLOCK_COROUTINES_INT_H */
|
#endif /* BLOCK_COROUTINES_INT_H */
|
||||||
|
|
72
block/io.c
72
block/io.c
|
@ -2475,28 +2475,50 @@ int bdrv_is_allocated_above(BlockDriverState *top,
|
||||||
}
|
}
|
||||||
|
|
||||||
int coroutine_fn
|
int coroutine_fn
|
||||||
bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
|
bdrv_co_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
|
||||||
bool is_read)
|
|
||||||
{
|
{
|
||||||
BlockDriver *drv = bs->drv;
|
BlockDriver *drv = bs->drv;
|
||||||
BlockDriverState *child_bs = bdrv_primary_bs(bs);
|
BlockDriverState *child_bs = bdrv_primary_bs(bs);
|
||||||
int ret = -ENOTSUP;
|
int ret = -ENOTSUP;
|
||||||
|
|
||||||
|
if (!drv) {
|
||||||
|
return -ENOMEDIUM;
|
||||||
|
}
|
||||||
|
|
||||||
bdrv_inc_in_flight(bs);
|
bdrv_inc_in_flight(bs);
|
||||||
|
|
||||||
if (!drv) {
|
if (drv->bdrv_load_vmstate) {
|
||||||
ret = -ENOMEDIUM;
|
ret = drv->bdrv_load_vmstate(bs, qiov, pos);
|
||||||
} else if (drv->bdrv_load_vmstate) {
|
|
||||||
if (is_read) {
|
|
||||||
ret = drv->bdrv_load_vmstate(bs, qiov, pos);
|
|
||||||
} else {
|
|
||||||
ret = drv->bdrv_save_vmstate(bs, qiov, pos);
|
|
||||||
}
|
|
||||||
} else if (child_bs) {
|
} else if (child_bs) {
|
||||||
ret = bdrv_co_rw_vmstate(child_bs, qiov, pos, is_read);
|
ret = bdrv_co_readv_vmstate(child_bs, qiov, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
bdrv_dec_in_flight(bs);
|
bdrv_dec_in_flight(bs);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int coroutine_fn
|
||||||
|
bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
|
||||||
|
{
|
||||||
|
BlockDriver *drv = bs->drv;
|
||||||
|
BlockDriverState *child_bs = bdrv_primary_bs(bs);
|
||||||
|
int ret = -ENOTSUP;
|
||||||
|
|
||||||
|
if (!drv) {
|
||||||
|
return -ENOMEDIUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
bdrv_inc_in_flight(bs);
|
||||||
|
|
||||||
|
if (drv->bdrv_save_vmstate) {
|
||||||
|
ret = drv->bdrv_save_vmstate(bs, qiov, pos);
|
||||||
|
} else if (child_bs) {
|
||||||
|
ret = bdrv_co_writev_vmstate(child_bs, qiov, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
bdrv_dec_in_flight(bs);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2504,38 +2526,18 @@ int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
|
||||||
int64_t pos, int size)
|
int64_t pos, int size)
|
||||||
{
|
{
|
||||||
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, size);
|
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, size);
|
||||||
int ret;
|
int ret = bdrv_writev_vmstate(bs, &qiov, pos);
|
||||||
|
|
||||||
ret = bdrv_writev_vmstate(bs, &qiov, pos);
|
return ret < 0 ? ret : size;
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
|
|
||||||
{
|
|
||||||
return bdrv_rw_vmstate(bs, qiov, pos, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
|
int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
|
||||||
int64_t pos, int size)
|
int64_t pos, int size)
|
||||||
{
|
{
|
||||||
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, size);
|
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, size);
|
||||||
int ret;
|
int ret = bdrv_readv_vmstate(bs, &qiov, pos);
|
||||||
|
|
||||||
ret = bdrv_readv_vmstate(bs, &qiov, pos);
|
return ret < 0 ? ret : size;
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
|
|
||||||
{
|
|
||||||
return bdrv_rw_vmstate(bs, qiov, pos, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************/
|
/**************************************************************/
|
||||||
|
|
|
@ -572,8 +572,10 @@ int path_has_protocol(const char *path);
|
||||||
int path_is_absolute(const char *path);
|
int path_is_absolute(const char *path);
|
||||||
char *path_combine(const char *base_path, const char *filename);
|
char *path_combine(const char *base_path, const char *filename);
|
||||||
|
|
||||||
int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
|
int generated_co_wrapper
|
||||||
int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
|
bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
|
||||||
|
int generated_co_wrapper
|
||||||
|
bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
|
||||||
int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
|
int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
|
||||||
int64_t pos, int size);
|
int64_t pos, int size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue