Re: [PATCH v4 07/25] assertions for block_int global state API
On 16.11.21 16:43, Emanuele Giuseppe Esposito wrote: On 12/11/2021 14:51, Hanna Reitz wrote: On 25.10.21 12:17, Emanuele Giuseppe Esposito wrote: Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi --- block.c | 17 + block/backup.c | 1 + block/block-backend.c | 3 +++ block/commit.c | 2 ++ block/dirty-bitmap.c | 1 + block/io.c | 6 ++ block/mirror.c | 4 block/monitor/bitmap-qmp-cmds.c | 6 ++ block/stream.c | 2 ++ blockdev.c | 7 +++ 10 files changed, 49 insertions(+) diff --git a/block.c b/block.c index 672f946065..41c5883c5c 100644 --- a/block.c +++ b/block.c [...] @@ -7473,6 +7488,7 @@ static bool append_strong_runtime_options(QDict *d, BlockDriverState *bs) * would result in exactly bs->backing. */ bool bdrv_backing_overridden(BlockDriverState *bs) { + assert(qemu_in_main_thread()); if (bs->backing) { return strcmp(bs->auto_backing_file, bs->backing->bs->filename); This function is in block_int-common.h, though. Can go as GS, since it is under BQL. (Actually, it is only used in block.c, so if you want I can put it as static). Otherwise, I will just move it to GS. Sounds good to me. Hanna
Re: [PATCH v4 07/25] assertions for block_int global state API
On 12/11/2021 14:51, Hanna Reitz wrote: On 25.10.21 12:17, Emanuele Giuseppe Esposito wrote: Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi --- block.c | 17 + block/backup.c | 1 + block/block-backend.c | 3 +++ block/commit.c | 2 ++ block/dirty-bitmap.c | 1 + block/io.c | 6 ++ block/mirror.c | 4 block/monitor/bitmap-qmp-cmds.c | 6 ++ block/stream.c | 2 ++ blockdev.c | 7 +++ 10 files changed, 49 insertions(+) diff --git a/block.c b/block.c index 672f946065..41c5883c5c 100644 --- a/block.c +++ b/block.c [...] @@ -7473,6 +7488,7 @@ static bool append_strong_runtime_options(QDict *d, BlockDriverState *bs) * would result in exactly bs->backing. */ bool bdrv_backing_overridden(BlockDriverState *bs) { + assert(qemu_in_main_thread()); if (bs->backing) { return strcmp(bs->auto_backing_file, bs->backing->bs->filename); This function is in block_int-common.h, though. Can go as GS, since it is under BQL. (Actually, it is only used in block.c, so if you want I can put it as static). Otherwise, I will just move it to GS. I agree with the rest. Thank you, Emanuele [...] diff --git a/block/io.c b/block/io.c index c5d7f8495e..f271ab3684 100644 --- a/block/io.c +++ b/block/io.c [...] @@ -3419,6 +3423,7 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *src, int64_t src_offset, { trace_bdrv_co_copy_range_from(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); + assert(qemu_in_main_thread()); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags, true); } This is a block_int-io.h function. @@ -3435,6 +3440,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset, { trace_bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); + assert(qemu_in_main_thread()); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags, false); } This, too. Hanna
Re: [PATCH v4 07/25] assertions for block_int global state API
On 25.10.21 12:17, Emanuele Giuseppe Esposito wrote: Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi --- block.c | 17 + block/backup.c | 1 + block/block-backend.c | 3 +++ block/commit.c | 2 ++ block/dirty-bitmap.c| 1 + block/io.c | 6 ++ block/mirror.c | 4 block/monitor/bitmap-qmp-cmds.c | 6 ++ block/stream.c | 2 ++ blockdev.c | 7 +++ 10 files changed, 49 insertions(+) diff --git a/block.c b/block.c index 672f946065..41c5883c5c 100644 --- a/block.c +++ b/block.c [...] @@ -7473,6 +7488,7 @@ static bool append_strong_runtime_options(QDict *d, BlockDriverState *bs) * would result in exactly bs->backing. */ bool bdrv_backing_overridden(BlockDriverState *bs) { +assert(qemu_in_main_thread()); if (bs->backing) { return strcmp(bs->auto_backing_file, bs->backing->bs->filename); This function is in block_int-common.h, though. [...] diff --git a/block/io.c b/block/io.c index c5d7f8495e..f271ab3684 100644 --- a/block/io.c +++ b/block/io.c [...] @@ -3419,6 +3423,7 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *src, int64_t src_offset, { trace_bdrv_co_copy_range_from(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); +assert(qemu_in_main_thread()); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags, true); } This is a block_int-io.h function. @@ -3435,6 +3440,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset, { trace_bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); +assert(qemu_in_main_thread()); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags, false); } This, too. Hanna
[PATCH v4 07/25] assertions for block_int global state API
Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi --- block.c | 17 + block/backup.c | 1 + block/block-backend.c | 3 +++ block/commit.c | 2 ++ block/dirty-bitmap.c| 1 + block/io.c | 6 ++ block/mirror.c | 4 block/monitor/bitmap-qmp-cmds.c | 6 ++ block/stream.c | 2 ++ blockdev.c | 7 +++ 10 files changed, 49 insertions(+) diff --git a/block.c b/block.c index 672f946065..41c5883c5c 100644 --- a/block.c +++ b/block.c @@ -653,6 +653,8 @@ int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv, Error *local_err = NULL; int ret; +assert(qemu_in_main_thread()); + size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); prealloc = qapi_enum_parse(&PreallocMode_lookup, buf, @@ -2428,6 +2430,8 @@ void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, uint64_t cumulative_perms = 0; uint64_t cumulative_shared_perms = BLK_PERM_ALL; +assert(qemu_in_main_thread()); + QLIST_FOREACH(c, &bs->parents, next_parent) { cumulative_perms |= c->perm; cumulative_shared_perms &= c->shared_perm; @@ -2486,6 +2490,8 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, Transaction *tran = tran_new(); int ret; +assert(qemu_in_main_thread()); + bdrv_child_set_perm(c, perm, shared, tran); ret = bdrv_refresh_perms(c->bs, &local_err); @@ -2516,6 +2522,8 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) uint64_t parent_perms, parent_shared; uint64_t perms, shared; +assert(qemu_in_main_thread()); + bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared); bdrv_child_perm(bs, c->bs, c, c->role, NULL, parent_perms, parent_shared, &perms, &shared); @@ -2658,6 +2666,7 @@ void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { +assert(qemu_in_main_thread()); if (role & BDRV_CHILD_FILTERED) { assert(!(role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA | BDRV_CHILD_COW))); @@ -2984,6 +2993,8 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, BdrvChild *child = NULL; Transaction *tran = tran_new(); +assert(qemu_in_main_thread()); + ret = bdrv_attach_child_common(child_bs, child_name, child_class, child_role, perm, shared_perm, opaque, &child, tran, errp); @@ -6027,6 +6038,8 @@ const char *bdrv_get_parent_name(const BlockDriverState *bs) BdrvChild *c; const char *name; +assert(qemu_in_main_thread()); + /* If multiple parents have a name, just pick the first one. */ QLIST_FOREACH(c, &bs->parents, next_parent) { if (c->klass->get_name) { @@ -7302,6 +7315,8 @@ bool bdrv_recurse_can_replace(BlockDriverState *bs, { BlockDriverState *filtered; +assert(qemu_in_main_thread()); + if (!bs || !bs->drv) { return false; } @@ -7473,6 +7488,7 @@ static bool append_strong_runtime_options(QDict *d, BlockDriverState *bs) * would result in exactly bs->backing. */ bool bdrv_backing_overridden(BlockDriverState *bs) { +assert(qemu_in_main_thread()); if (bs->backing) { return strcmp(bs->auto_backing_file, bs->backing->bs->filename); @@ -7861,6 +7877,7 @@ static BlockDriverState *bdrv_do_skip_filters(BlockDriverState *bs, */ BlockDriverState *bdrv_skip_implicit_filters(BlockDriverState *bs) { +assert(qemu_in_main_thread()); return bdrv_do_skip_filters(bs, true); } diff --git a/block/backup.c b/block/backup.c index 21d5983779..c53041772c 100644 --- a/block/backup.c +++ b/block/backup.c @@ -372,6 +372,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, assert(bs); assert(target); +assert(qemu_in_main_thread()); /* QMP interface protects us from these cases */ assert(sync_mode != MIRROR_SYNC_MODE_INCREMENTAL); diff --git a/block/block-backend.c b/block/block-backend.c index ed45576007..fa30bb88ea 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1087,6 +1087,7 @@ static void blk_root_change_media(BdrvChild *child, bool load) */ bool blk_dev_has_removable_media(BlockBackend *blk) { +assert(qemu_in_main_thread()); return !blk->dev || (blk->dev_ops && blk->dev_ops->change_media_cb); } @@ -1104,6 +1105,7 @@ bool blk_dev_has_tray(BlockBackend *blk) */ void blk_dev_eject_request(BlockBackend *blk, bool force) { +assert(qemu_in_main_thread()); if (blk->dev_ops && blk->dev_ops->eject_request_cb) {