From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:60942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RHCIC-0004Xs-I8 for qemu-devel@nongnu.org; Fri, 21 Oct 2011 06:25:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RHCIB-0004rH-2z for qemu-devel@nongnu.org; Fri, 21 Oct 2011 06:25:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35163) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RHCIA-0004r9-Oj for qemu-devel@nongnu.org; Fri, 21 Oct 2011 06:25:35 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9LAPXxP020091 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Oct 2011 06:25:34 -0400 From: Kevin Wolf Date: Fri, 21 Oct 2011 12:28:22 +0200 Message-Id: <1319192902-16625-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH] block: Add !qemu_in_coroutine() assertions to synchronous functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com 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 --- 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