Patchwork block: Add !qemu_in_coroutine() assertions to synchronous functions

login
register
mail settings
Submitter Kevin Wolf
Date Oct. 21, 2011, 10:28 a.m.
Message ID <1319192902-16625-1-git-send-email-kwolf@redhat.com>
Download mbox | patch
Permalink /patch/120973/
State New
Headers show

Comments

Kevin Wolf - Oct. 21, 2011, 10:28 a.m.
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(-)

Patch

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;
     }