[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v2 05/15] Make qcow2_open synchronous
From: |
Charlie Shepherd |
Subject: |
[Qemu-devel] [RFC v2 05/15] Make qcow2_open synchronous |
Date: |
Fri, 9 Aug 2013 19:43:55 +0200 |
The previous patch convert all .bdrv_open functions to run from a coroutine
context. However
qcow2's open method is also called from qcow2_invalidate_cache.
bdrv_invalidate_cache is mainly
called by migration.c, which doesn't run in coroutine context, so rather than
propagating
coroutine_fn annotations up the call chain, turn qcow2_open into a synchronous
wrapper.
Signed-off-by: Charlie Shepherd <address@hidden>
---
block/qcow2.c | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index c6dc209..59c4200 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -58,6 +58,10 @@ typedef struct {
#define QCOW2_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA
#define QCOW2_EXT_MAGIC_FEATURE_TABLE 0x6803f857
+
+#define NOT_DONE 0x7fffffff
+
+
static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename)
{
const QCowHeader *cow_header = (const void *)buf;
@@ -315,7 +319,7 @@ static QemuOptsList qcow2_runtime_opts = {
},
};
-static int qcow2_open(BlockDriverState *bs, QDict *options, int flags)
+static int coroutine_fn qcow2_co_open(BlockDriverState *bs, QDict *options,
int flags)
{
BDRVQcowState *s = bs->opaque;
int len, i, ret = 0;
@@ -590,6 +594,38 @@ static int qcow2_open(BlockDriverState *bs, QDict
*options, int flags)
return ret;
}
+struct QOpenCo {
+ BlockDriverState *bs;
+ QDict *options;
+ int flags;
+ int ret;
+};
+
+static void coroutine_fn qcow2_co_open_entry(void *opaque)
+{
+ struct QOpenCo *qo = opaque;
+
+ qo->ret = qcow2_co_open(qo->bs, qo->options, qo->flags);
+}
+
+static int qcow2_open(BlockDriverState *bs, QDict *options, int flags)
+{
+ Coroutine *co;
+ struct QOpenCo qo = {
+ .bs = bs,
+ .options = options,
+ .flags = flags,
+ .ret = NOT_DONE,
+ };
+
+ co = qemu_coroutine_create(qcow2_co_open_entry);
+ qemu_coroutine_enter(co, &qo);
+ while (qo.ret == NOT_DONE) {
+ qemu_aio_wait();
+ }
+ return qo.ret;
+}
+
static int qcow2_set_key(BlockDriverState *bs, const char *key)
{
BDRVQcowState *s = bs->opaque;
--
1.8.3.2
- [Qemu-devel] [RFC v2 01/15] Add an explanation of when a function should be marked coroutine_fn, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 02/15] Rename qemu_coroutine_self to qemu_coroutine_self_int and add an annotated wrapper, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 03/15] Explicitly mark BlockDriver function .bdrv_create as coroutine and rename it bdrv_co_create., Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 05/15] Make qcow2_open synchronous,
Charlie Shepherd <=
- [Qemu-devel] [RFC v2 04/15] Convert .bdrv_open and .bdrv_file_open to coroutine_fn, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 07/15] Call bdrv->open via a synchronous wrapper in block/snapshot.c, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 06/15] Explicitly mark BlockDriver functions .bdrv_write and .bdrv_read as coroutine functions, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 08/15] Convert bdrv_create and associated functions to be coroutine_fn, Charlie Shepherd, 2013/08/09