qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH] block: Add !qemu_in_coroutine() assertions to synchronous functions
Date: Fri, 21 Oct 2011 12:28:22 +0200	[thread overview]
Message-ID: <1319192902-16625-1-git-send-email-kwolf@redhat.com> (raw)

When adding the locking, we came to the conclusion that converting
read/write/flush/discard to coroutines should be enough because everything else
isn't called in coroutine context. Add assertions to spell this assumption out
and ensure that it won't be broken accidentally.

And even if we have missed converting a valid case, aborting qemu is better
than corrupting images.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index 70aab63..11c7f91 100644
--- a/block.c
+++ b/block.c
@@ -849,6 +849,8 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res)
         return -ENOTSUP;
     }
 
+    assert(!qemu_in_coroutine());
+
     memset(res, 0, sizeof(*res));
     return bs->drv->bdrv_check(bs, res);
 }
@@ -867,6 +869,8 @@ int bdrv_commit(BlockDriverState *bs)
     char filename[1024];
     BlockDriverState *bs_rw, *bs_ro;
 
+    assert(!qemu_in_coroutine());
+
     if (!drv)
         return -ENOMEDIUM;
     
@@ -926,6 +930,7 @@ int bdrv_commit(BlockDriverState *bs)
         }
     }
 
+    assert(!qemu_in_coroutine());
     if (drv->bdrv_make_empty) {
         ret = drv->bdrv_make_empty(bs);
         bdrv_flush(bs);
@@ -983,6 +988,8 @@ int bdrv_change_backing_file(BlockDriverState *bs,
 {
     BlockDriver *drv = bs->drv;
 
+    assert(!qemu_in_coroutine());
+
     if (drv->bdrv_change_backing_file != NULL) {
         return drv->bdrv_change_backing_file(bs, backing_file, backing_fmt);
     } else {
@@ -1323,6 +1330,8 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)
         return -EACCES;
     if (bdrv_in_use(bs))
         return -EBUSY;
+
+    assert(!qemu_in_coroutine());
     ret = drv->bdrv_truncate(bs, offset);
     if (ret == 0) {
         ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);
@@ -1792,6 +1801,8 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
         *pnum = (n < nb_sectors) ? (n) : (nb_sectors);
         return 1;
     }
+
+    assert(!qemu_in_coroutine());
     return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum);
 }
 
@@ -2050,12 +2061,16 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
         set_dirty_bitmap(bs, sector_num, nb_sectors, 1);
     }
 
+    assert(!qemu_in_coroutine());
     return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors);
 }
 
 int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
 {
     BlockDriver *drv = bs->drv;
+
+    assert(!qemu_in_coroutine());
+
     if (!drv)
         return -ENOMEDIUM;
     if (!drv->bdrv_get_info)
@@ -2068,6 +2083,9 @@ int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
                       int64_t pos, int size)
 {
     BlockDriver *drv = bs->drv;
+
+    assert(!qemu_in_coroutine());
+
     if (!drv)
         return -ENOMEDIUM;
     if (drv->bdrv_save_vmstate)
@@ -2081,6 +2099,9 @@ int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
                       int64_t pos, int size)
 {
     BlockDriver *drv = bs->drv;
+
+    assert(!qemu_in_coroutine());
+
     if (!drv)
         return -ENOMEDIUM;
     if (drv->bdrv_load_vmstate)
@@ -2149,6 +2170,9 @@ int bdrv_snapshot_create(BlockDriverState *bs,
                          QEMUSnapshotInfo *sn_info)
 {
     BlockDriver *drv = bs->drv;
+
+    assert(!qemu_in_coroutine());
+
     if (!drv)
         return -ENOMEDIUM;
     if (drv->bdrv_snapshot_create)
@@ -2164,6 +2188,8 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
     BlockDriver *drv = bs->drv;
     int ret, open_ret;
 
+    assert(!qemu_in_coroutine());
+
     if (!drv)
         return -ENOMEDIUM;
     if (drv->bdrv_snapshot_goto)
@@ -2187,6 +2213,9 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
 int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
 {
     BlockDriver *drv = bs->drv;
+
+    assert(!qemu_in_coroutine());
+
     if (!drv)
         return -ENOMEDIUM;
     if (drv->bdrv_snapshot_delete)
@@ -2200,6 +2229,9 @@ int bdrv_snapshot_list(BlockDriverState *bs,
                        QEMUSnapshotInfo **psn_info)
 {
     BlockDriver *drv = bs->drv;
+
+    assert(!qemu_in_coroutine());
+
     if (!drv)
         return -ENOMEDIUM;
     if (drv->bdrv_snapshot_list)
@@ -2213,6 +2245,9 @@ int bdrv_snapshot_load_tmp(BlockDriverState *bs,
         const char *snapshot_name)
 {
     BlockDriver *drv = bs->drv;
+
+    assert(!qemu_in_coroutine());
+
     if (!drv) {
         return -ENOMEDIUM;
     }
-- 
1.7.6.4

                 reply	other threads:[~2011-10-21 10:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1319192902-16625-1-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=pbonzini@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).