[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC][PATCH 09/12] block: Add bdrv_co_readv() and bdrv_co_w
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [RFC][PATCH 09/12] block: Add bdrv_co_readv() and bdrv_co_writev() |
Date: |
Sat, 22 Jan 2011 09:29:24 +0000 |
Add coroutine versions of the bdrv_aio_readv() and bdrv_aio_writev()
functions. The coroutine version doesn't take a callback and simply
returns the error value. Behind the scenes they are implemented using
bdrv_aio_readv() and bdrv_aio_writev().
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
block.h | 7 +++++++
2 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/block.c b/block.c
index ff2795b..ecb6538 100644
--- a/block.c
+++ b/block.c
@@ -2614,6 +2614,57 @@ void qemu_aio_release(void *p)
}
/**************************************************************/
+/* I/O for coroutines */
+
+typedef struct CoroutineIOCompletion {
+ Coroutine *coroutine;
+ int ret;
+} CoroutineIOCompletion;
+
+static void bdrv_co_complete(void *opaque, int ret)
+{
+ CoroutineIOCompletion *co = opaque;
+
+ co->ret = ret;
+ qemu_coroutine_enter(co->coroutine, NULL);
+}
+
+static int coroutine_fn bdrv_co_io(BlockDriverState *bs, int64_t sector_num,
+ QEMUIOVector *iov, int nb_sectors,
+ int is_write)
+{
+ CoroutineIOCompletion co = {
+ .coroutine = qemu_coroutine_self(),
+ };
+ BlockDriverAIOCB *acb;
+
+ if (is_write) {
+ acb = bdrv_aio_writev(bs, sector_num, iov, nb_sectors,
+ bdrv_co_complete, &co);
+ } else {
+ acb = bdrv_aio_readv(bs, sector_num, iov, nb_sectors,
+ bdrv_co_complete, &co);
+ }
+ if (!acb) {
+ return -EIO;
+ }
+ qemu_coroutine_yield(NULL);
+ return co.ret;
+}
+
+int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
+ QEMUIOVector *iov, int nb_sectors)
+{
+ return bdrv_co_io(bs, sector_num, iov, nb_sectors, 0);
+}
+
+int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
+ QEMUIOVector *iov, int nb_sectors)
+{
+ return bdrv_co_io(bs, sector_num, iov, nb_sectors, 1);
+}
+
+/**************************************************************/
/* removable device support */
/**
diff --git a/block.h b/block.h
index f923add..472e3d4 100644
--- a/block.h
+++ b/block.h
@@ -4,6 +4,7 @@
#include "qemu-aio.h"
#include "qemu-common.h"
#include "qemu-option.h"
+#include "qemu-coroutine.h"
#include "qobject.h"
/* block.c */
@@ -120,6 +121,12 @@ BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState *bs,
BlockDriverCompletionFunc *cb, void *opaque);
void bdrv_aio_cancel(BlockDriverAIOCB *acb);
+/* block I/O for coroutines */
+int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
+ QEMUIOVector *iov, int nb_sectors);
+int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
+ QEMUIOVector *iov, int nb_sectors);
+
typedef struct BlockRequest {
/* Fields to be filled by multiwrite caller */
int64_t sector;
--
1.7.2.3
- [Qemu-devel] [RFC][PATCH 00/12] qcow2: Convert qcow2 to use coroutines for async I/O, Stefan Hajnoczi, 2011/01/22
- [Qemu-devel] [RFC][PATCH 07/12] coroutine: Add coroutine_is_leader(), Stefan Hajnoczi, 2011/01/22
- [Qemu-devel] [RFC][PATCH 08/12] coroutine: Add qemu_in_coroutine(), Stefan Hajnoczi, 2011/01/22
- [Qemu-devel] [RFC][PATCH 04/12] coroutine: Use thread-local leader and current variables, Stefan Hajnoczi, 2011/01/22
- [Qemu-devel] [RFC][PATCH 09/12] block: Add bdrv_co_readv() and bdrv_co_writev(),
Stefan Hajnoczi <=
- [Qemu-devel] [RFC][PATCH 10/12] block: Add coroutine support to synchronous I/O functions, Stefan Hajnoczi, 2011/01/22
- [Qemu-devel] [RFC][PATCH 06/12] coroutine: Add qemu_coroutine_self(), Stefan Hajnoczi, 2011/01/22
- [Qemu-devel] [RFC][PATCH 12/12] qcow2: Serialize all requests, Stefan Hajnoczi, 2011/01/22
- [Qemu-devel] [RFC][PATCH 05/12] coroutine: Add coroutines, Stefan Hajnoczi, 2011/01/22
- [Qemu-devel] [RFC][PATCH 11/12] qcow2: Convert qcow2 to use coroutines for async I/O, Stefan Hajnoczi, 2011/01/22