From: Charlie Shepherd <charlie@ctshepherd.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@gmail.com, gabriel@kerneis.info,
Charlie Shepherd <charlie@ctshepherd.com>,
pbonzini@redhat.com
Subject: [Qemu-devel] [RFC v2 07/15] Call bdrv->open via a synchronous wrapper in block/snapshot.c
Date: Fri, 9 Aug 2013 19:43:57 +0200 [thread overview]
Message-ID: <1376070245-22557-7-git-send-email-charlie@ctshepherd.com> (raw)
In-Reply-To: <1376070245-22557-1-git-send-email-charlie@ctshepherd.com>
block/snapshot.c calls bdrv->open directly from a non-coroutine context. Provide a synchronous
wrapper to ensure correctness.
Signed-off-by: Charlie Shepherd <charlie@ctshepherd.com>
---
block/snapshot.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/block/snapshot.c b/block/snapshot.c
index 6c6d9de..541d83d 100644
--- a/block/snapshot.c
+++ b/block/snapshot.c
@@ -25,6 +25,8 @@
#include "block/snapshot.h"
#include "block/block_int.h"
+#define NOT_DONE 0x7fffffff
+
int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
const char *name)
{
@@ -81,6 +83,34 @@ int bdrv_snapshot_create(BlockDriverState *bs,
return -ENOTSUP;
}
+struct SnapOp {
+ BlockDriverState *bs;
+ int ret;
+};
+
+static void coroutine_fn bdrv_snapshot_open_entry(void *opaque)
+{
+ struct SnapOp *so = opaque;
+ so->ret = so->bs->drv->bdrv_co_open(so->bs, NULL, so->bs->open_flags);
+}
+
+static int bdrv_snapshot_open(BlockDriverState *bs)
+{
+ Coroutine *co;
+ struct SnapOp so = {
+ .bs = bs,
+ .ret = NOT_DONE,
+ };
+
+ co = qemu_coroutine_create(bdrv_snapshot_open_entry);
+ qemu_coroutine_enter(co, &so);
+ while (so.ret == NOT_DONE) {
+ qemu_aio_wait();
+ }
+
+ return so.ret;
+}
+
int bdrv_snapshot_goto(BlockDriverState *bs,
const char *snapshot_id)
{
@@ -97,7 +127,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
if (bs->file) {
drv->bdrv_close(bs);
ret = bdrv_snapshot_goto(bs->file, snapshot_id);
- open_ret = drv->bdrv_open(bs, NULL, bs->open_flags);
+ open_ret = bdrv_snapshot_open(bs);
if (open_ret < 0) {
bdrv_delete(bs->file);
bs->drv = NULL;
--
1.8.3.2
next prev parent reply other threads:[~2013-08-09 17:45 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-09 17:43 [Qemu-devel] [RFC v2 01/15] Add an explanation of when a function should be marked coroutine_fn Charlie Shepherd
2013-08-09 17:43 ` [Qemu-devel] [RFC v2 02/15] Rename qemu_coroutine_self to qemu_coroutine_self_int and add an annotated wrapper Charlie Shepherd
2013-08-14 14:21 ` Stefan Hajnoczi
2013-08-09 17:43 ` [Qemu-devel] [RFC v2 03/15] Explicitly mark BlockDriver function .bdrv_create as coroutine and rename it bdrv_co_create Charlie Shepherd
2013-08-14 14:26 ` Stefan Hajnoczi
2013-08-09 17:43 ` [Qemu-devel] [RFC v2 04/15] Convert .bdrv_open and .bdrv_file_open to coroutine_fn Charlie Shepherd
2013-08-29 12:11 ` Stefan Hajnoczi
2013-08-29 12:16 ` Charlie Shepherd
2013-08-09 17:43 ` [Qemu-devel] [RFC v2 05/15] Make qcow2_open synchronous Charlie Shepherd
2013-08-29 12:29 ` Stefan Hajnoczi
2013-08-29 12:33 ` Stefan Hajnoczi
2013-08-29 12:43 ` Charlie Shepherd
2013-09-04 11:39 ` Stefan Hajnoczi
2013-08-09 17:43 ` [Qemu-devel] [RFC v2 06/15] Explicitly mark BlockDriver functions .bdrv_write and .bdrv_read as coroutine functions Charlie Shepherd
2013-08-09 17:43 ` Charlie Shepherd [this message]
2013-08-29 15:14 ` [Qemu-devel] [RFC v2 07/15] Call bdrv->open via a synchronous wrapper in block/snapshot.c Stefan Hajnoczi
2013-08-09 17:43 ` [Qemu-devel] [RFC v2 08/15] Convert bdrv_create and associated functions to be coroutine_fn Charlie Shepherd
2013-08-29 15:31 ` Stefan Hajnoczi
2013-08-09 17:43 ` [Qemu-devel] [RFC v2 09/15] Add a synchronous wrapper bdrv_sync_rwco Charlie Shepherd
2013-08-29 15:32 ` Stefan Hajnoczi
2013-08-09 17:44 ` [Qemu-devel] [RFC v2 10/15] Convert bdrv_read, bdrv_write and associated functions to coroutine functions Charlie Shepherd
2013-08-09 17:44 ` [Qemu-devel] [RFC v2 11/15] Make bdrv_discard coroutine only and add bdrv_sync_discard Charlie Shepherd
2013-08-09 17:44 ` [Qemu-devel] [RFC v2 12/15] Make bdrv_flush coroutine only and add bdrv_sync_flush Charlie Shepherd
2013-08-09 17:44 ` [Qemu-devel] [RFC v2 13/15] Introduce a run_handler function in qemu-img.c Charlie Shepherd
2013-08-09 17:44 ` [Qemu-devel] [RFC v2 14/15] Add coroutine annotations for qemu_co_rwlock_rdlock and qemu_co_rwlock_wrlock Charlie Shepherd
2013-08-09 17:44 ` [Qemu-devel] [RFC v2 15/15] Add coroutine_fn annotations to nbd_co_* functions Charlie Shepherd
2013-08-14 14:14 ` [Qemu-devel] [RFC v2 01/15] Add an explanation of when a function should be marked coroutine_fn Stefan Hajnoczi
2013-08-29 15:34 ` Stefan Hajnoczi
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=1376070245-22557-7-git-send-email-charlie@ctshepherd.com \
--to=charlie@ctshepherd.com \
--cc=gabriel@kerneis.info \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/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).