From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, kwolf@redhat.com
Subject: [Qemu-devel] [PATCH 1/5] qcow2: make qcow2_do_open a coroutine_fn
Date: Mon, 10 Jul 2017 18:58:23 +0200 [thread overview]
Message-ID: <20170710165827.4250-2-pbonzini@redhat.com> (raw)
In-Reply-To: <20170710165827.4250-1-pbonzini@redhat.com>
It is called from qcow2_invalidate_cache in coroutine context, so always
load metadata from a coroutine.
---
block/qcow2.c | 45 ++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 40 insertions(+), 5 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index cb081ea47f..b5de67d113 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -814,8 +814,8 @@ static int qcow2_update_options(BlockDriverState *bs, QDict *options,
return ret;
}
-static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,
- Error **errp)
+static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
+ int flags, Error **errp)
{
BDRVQcow2State *s = bs->opaque;
unsigned int len, i;
@@ -1161,8 +1161,6 @@ static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,
}
}
- /* Initialise locks */
- qemu_co_mutex_init(&s->lock);
bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP;
/* Repair image if dirty */
@@ -1205,16 +1203,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.0
next prev parent reply other threads:[~2017-07-10 16:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-10 16:58 [Qemu-devel] [RFC PATCH 0/5] move bdrv_invalidate_cache, bdrv_check to coroutines Paolo Bonzini
2017-07-10 16:58 ` Paolo Bonzini [this message]
2017-07-11 8:28 ` [Qemu-devel] [PATCH 1/5] qcow2: make qcow2_do_open a coroutine_fn Kevin Wolf
2017-07-11 8:34 ` Paolo Bonzini
2017-07-11 9:07 ` Kevin Wolf
2017-07-11 9:09 ` Paolo Bonzini
2017-07-10 16:58 ` [Qemu-devel] [PATCH 2/5] qed: make bdrv_qed_do_open " Paolo Bonzini
2017-07-10 16:58 ` [Qemu-devel] [PATCH 3/5] block: convert bdrv_invalidate_cache callback to coroutine_fn Paolo Bonzini
2017-07-11 8:24 ` Kevin Wolf
2017-07-11 8:33 ` Paolo Bonzini
2017-07-11 8:39 ` Kevin Wolf
2017-07-11 8:41 ` Paolo Bonzini
2017-07-11 9:03 ` Kevin Wolf
2017-07-10 16:58 ` [Qemu-devel] [PATCH 4/5] qcow2: introduce qcow2_write_caches and qcow2_flush_caches Paolo Bonzini
2017-07-10 16:58 ` [Qemu-devel] [PATCH 5/5] block: convert bdrv_check callback to coroutine_fn Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170710165827.4250-2-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=kwolf@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).