[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 04/56] qcow2: make qcow2_do_open a coroutine_fn
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 04/56] qcow2: make qcow2_do_open a coroutine_fn |
Date: |
Fri, 9 Mar 2018 17:18:41 +0100 |
From: Paolo Bonzini <address@hidden>
It is called from qcow2_invalidate_cache in coroutine context (incoming
migration runs in a coroutine), so it's cleaner if metadata is always
loaded from a coroutine.
Signed-off-by: Paolo Bonzini <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2.c | 46 +++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 41 insertions(+), 5 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index ee040a49cd..4ac1a45e61 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1118,8 +1118,9 @@ static int qcow2_update_options(BlockDriverState *bs,
QDict *options,
return ret;
}
-static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,
- Error **errp)
+/* Called with s->lock held. */
+static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
+ int flags, Error **errp)
{
BDRVQcow2State *s = bs->opaque;
unsigned int len, i;
@@ -1498,8 +1499,6 @@ static int qcow2_do_open(BlockDriverState *bs, QDict
*options, int flags,
}
}
- /* Initialise locks */
- qemu_co_mutex_init(&s->lock);
bs->supported_zero_flags = header.version >= 3 ? BDRV_REQ_MAY_UNMAP : 0;
/* Repair image if dirty */
@@ -1545,16 +1544,53 @@ static int qcow2_do_open(BlockDriverState *bs, QDict
*options, int flags,
return ret;
}
+typedef struct QCow2OpenCo {
+ BlockDriverState *bs;
+ QDict *options;
+ int flags;
+ Error **errp;
+ int ret;
+} QCow2OpenCo;
+
+static void coroutine_fn qcow2_open_entry(void *opaque)
+{
+ QCow2OpenCo *qoc = opaque;
+ BDRVQcow2State *s = qoc->bs->opaque;
+
+ qemu_co_mutex_lock(&s->lock);
+ qoc->ret = qcow2_do_open(qoc->bs, qoc->options, qoc->flags, qoc->errp);
+ qemu_co_mutex_unlock(&s->lock);
+}
+
static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
+ BDRVQcow2State *s = bs->opaque;
+ QCow2OpenCo qoc = {
+ .bs = bs,
+ .options = options,
+ .flags = flags,
+ .errp = errp,
+ .ret = -EINPROGRESS
+ };
+
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
false, errp);
if (!bs->file) {
return -EINVAL;
}
- return qcow2_do_open(bs, options, flags, errp);
+ /* Initialise locks */
+ qemu_co_mutex_init(&s->lock);
+
+ if (qemu_in_coroutine()) {
+ /* From bdrv_co_create. */
+ qcow2_open_entry(&qoc);
+ } else {
+ qemu_coroutine_enter(qemu_coroutine_create(qcow2_open_entry, &qoc));
+ BDRV_POLL_WHILE(bs, qoc.ret == -EINPROGRESS);
+ }
+ return qoc.ret;
}
static void qcow2_refresh_limits(BlockDriverState *bs, Error **errp)
--
2.13.6
- [Qemu-devel] [PULL 00/56] Block layer patches, Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 01/56] block: implement the bdrv_reopen_prepare helper for LUKS driver, Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 02/56] qcow2: introduce qcow2_write_caches and qcow2_flush_caches, Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 03/56] qcow2: fix flushing after dirty bitmap metadata writes, Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 09/56] qcow2: Check L1 table offset in qcow2_snapshot_load_tmp(), Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 07/56] block: convert bdrv_check callback to coroutine_fn, Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 11/56] qcow2: Check snapshot L1 tables in qcow2_check_metadata_overlap(), Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 05/56] qed: make bdrv_qed_do_open a coroutine_fn, Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 04/56] qcow2: make qcow2_do_open a coroutine_fn,
Kevin Wolf <=
- [Qemu-devel] [PULL 16/56] block/qapi: Add qcow2 create options to schema, Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 17/56] qcow2: Rename qcow2_co_create2() to qcow2_co_create(), Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 10/56] qcow2: Check L1 table parameters in qcow2_expand_zero_clusters(), Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 15/56] block/qapi: Introduce BlockdevCreateOptions, Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 22/56] qcow2: Handle full/falloc preallocation in qcow2_co_create(), Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 08/56] qcow2: Generalize validate_table_offset() into qcow2_validate_table(), Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 12/56] qcow2: Check snapshot L1 table in qcow2_snapshot_goto(), Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 13/56] qcow2: Check snapshot L1 table in qcow2_snapshot_delete(), Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 14/56] qcow2: Make qemu-img check detect corrupted L1 tables in snapshots, Kevin Wolf, 2018/03/09
- [Qemu-devel] [PULL 06/56] block: convert bdrv_invalidate_cache callback to coroutine_fn, Kevin Wolf, 2018/03/09