qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] block: Add !qemu_in_coroutine() assertions to synch


From: Kevin Wolf
Subject: [Qemu-devel] [PATCH] block: Add !qemu_in_coroutine() assertions to synchronous functions
Date: Fri, 21 Oct 2011 12:28:22 +0200

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 <address@hidden>
---
 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 via email to

[Prev in Thread] Current Thread [Next in Thread]