[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 24/39] block: Make bdrv_load/save_vmstate coroutine_f
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 24/39] block: Make bdrv_load/save_vmstate coroutine_fns |
Date: |
Thu, 16 Jun 2016 16:08:13 +0200 |
This allows drivers to share code between normal I/O and vmstate
accesses.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
---
block/io.c | 80 ++++++++++++++++++++++++++++++++++-------------
include/block/block_int.h | 10 +++---
2 files changed, 64 insertions(+), 26 deletions(-)
diff --git a/block/io.c b/block/io.c
index af4d43e..e1e8948 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1840,6 +1840,62 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t
sector_num,
return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors);
}
+typedef struct BdrvVmstateCo {
+ BlockDriverState *bs;
+ QEMUIOVector *qiov;
+ int64_t pos;
+ bool is_read;
+ int ret;
+} BdrvVmstateCo;
+
+static int coroutine_fn
+bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
+ bool is_read)
+{
+ BlockDriver *drv = bs->drv;
+
+ if (!drv) {
+ return -ENOMEDIUM;
+ } else if (drv->bdrv_load_vmstate) {
+ return is_read ? drv->bdrv_load_vmstate(bs, qiov, pos)
+ : drv->bdrv_save_vmstate(bs, qiov, pos);
+ } else if (bs->file) {
+ return bdrv_co_rw_vmstate(bs->file->bs, qiov, pos, is_read);
+ }
+
+ return -ENOTSUP;
+}
+
+static void coroutine_fn bdrv_co_rw_vmstate_entry(void *opaque)
+{
+ BdrvVmstateCo *co = opaque;
+ co->ret = bdrv_co_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read);
+}
+
+static inline int
+bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
+ bool is_read)
+{
+ if (qemu_in_coroutine()) {
+ return bdrv_co_rw_vmstate(bs, qiov, pos, is_read);
+ } else {
+ BdrvVmstateCo data = {
+ .bs = bs,
+ .qiov = qiov,
+ .pos = pos,
+ .is_read = is_read,
+ .ret = -EINPROGRESS,
+ };
+ Coroutine *co = qemu_coroutine_create(bdrv_co_rw_vmstate_entry);
+
+ qemu_coroutine_enter(co, &data);
+ while (data.ret == -EINPROGRESS) {
+ aio_poll(bdrv_get_aio_context(bs), true);
+ }
+ return data.ret;
+ }
+}
+
int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
int64_t pos, int size)
{
@@ -1862,17 +1918,7 @@ int bdrv_save_vmstate(BlockDriverState *bs, const
uint8_t *buf,
int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
{
- BlockDriver *drv = bs->drv;
-
- if (!drv) {
- return -ENOMEDIUM;
- } else if (drv->bdrv_save_vmstate) {
- return drv->bdrv_save_vmstate(bs, qiov, pos);
- } else if (bs->file) {
- return bdrv_writev_vmstate(bs->file->bs, qiov, pos);
- }
-
- return -ENOTSUP;
+ return bdrv_rw_vmstate(bs, qiov, pos, false);
}
int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
@@ -1896,17 +1942,7 @@ int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
{
- BlockDriver *drv = bs->drv;
-
- if (!drv) {
- return -ENOMEDIUM;
- } else if (drv->bdrv_load_vmstate) {
- return drv->bdrv_load_vmstate(bs, qiov, pos);
- } else if (bs->file) {
- return bdrv_readv_vmstate(bs->file->bs, qiov, pos);
- }
-
- return -ENOTSUP;
+ return bdrv_rw_vmstate(bs, qiov, pos, true);
}
/**************************************************************/
diff --git a/include/block/block_int.h b/include/block/block_int.h
index f9a32cc..1fe0811 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -224,10 +224,12 @@ struct BlockDriver {
int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
ImageInfoSpecific *(*bdrv_get_specific_info)(BlockDriverState *bs);
- int (*bdrv_save_vmstate)(BlockDriverState *bs, QEMUIOVector *qiov,
- int64_t pos);
- int (*bdrv_load_vmstate)(BlockDriverState *bs, QEMUIOVector *qiov,
- int64_t pos);
+ int coroutine_fn (*bdrv_save_vmstate)(BlockDriverState *bs,
+ QEMUIOVector *qiov,
+ int64_t pos);
+ int coroutine_fn (*bdrv_load_vmstate)(BlockDriverState *bs,
+ QEMUIOVector *qiov,
+ int64_t pos);
int (*bdrv_change_backing_file)(BlockDriverState *bs,
const char *backing_file, const char *backing_fmt);
--
1.8.3.1
- [Qemu-devel] [PULL 12/39] block: drop support for using qcow[2] encryption with system emulators, (continued)
- [Qemu-devel] [PULL 12/39] block: drop support for using qcow[2] encryption with system emulators, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 08/39] m25p80: fix test on blk_pread() return value, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 09/39] qemu-img bench: Fix uninitialised writethrough mode, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 10/39] block: Avoid bogus flags during mirroring, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 13/39] block: Byte-based bdrv_co_do_copy_on_readv(), Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 19/39] linux-aio: Cancel BH if not needed, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 20/39] doc: Fix mailing list address in tests/qemu-iotests/README, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 16/39] raw-posix: Switch to bdrv_co_* interfaces, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 18/39] block: Don't enforce 512 byte minimum alignment, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 21/39] block: Introduce bdrv_preadv(), Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 24/39] block: Make bdrv_load/save_vmstate coroutine_fns,
Kevin Wolf <=
- [Qemu-devel] [PULL 17/39] raw-posix: Implement .bdrv_co_preadv/pwritev, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 23/39] block: Allow .bdrv_load/save_vmstate() to return 0/-errno, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 30/39] block: Prevent sleeping jobs from resuming if they have been paused, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 22/39] block: Make .bdrv_load_vmstate() vectored, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 29/39] block: use the block job list in qmp_query_block_jobs(), Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 25/39] qcow2: Let vmstate call qcow2_co_preadv/pwrite directly, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 27/39] block: Fix snapshot=on with aio=native, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 28/39] block: use the block job list in bdrv_drain_all(), Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 26/39] block: Remove bs->zero_beyond_eof, Kevin Wolf, 2016/06/16
- [Qemu-devel] [PULL 31/39] block: Create the commit block job before reopening any image, Kevin Wolf, 2016/06/16