aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2023-02-03 16:21:59 +0100
committerKevin Wolf <kwolf@redhat.com>2023-02-23 19:49:29 +0100
commitd9249c253c28ef836641bea98180784fc2e9f655 (patch)
treeb06ec60ff519c9ef51e946fc6bf40270886724c3
parent79a292e5ec767eea27a0cc456570ee028f4e3972 (diff)
downloadqemu-d9249c253c28ef836641bea98180784fc2e9f655.zip
qemu-d9249c253c28ef836641bea98180784fc2e9f655.tar.gz
qemu-d9249c253c28ef836641bea98180784fc2e9f655.tar.bz2
block: Mark bdrv_(un)register_buf() GRAPH_RDLOCK
This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_register_buf() and bdrv_unregister_buf() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20230203152202.49054-21-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r--block/io.c14
-rw-r--r--include/block/block_int-common.h7
2 files changed, 14 insertions, 7 deletions
diff --git a/block/io.c b/block/io.c
index b5459c2..8974d46 100644
--- a/block/io.c
+++ b/block/io.c
@@ -3187,13 +3187,15 @@ void coroutine_fn bdrv_co_io_unplug(BlockDriverState *bs)
}
/* Helper that undoes bdrv_register_buf() when it fails partway through */
-static void bdrv_register_buf_rollback(BlockDriverState *bs,
- void *host,
- size_t size,
- BdrvChild *final_child)
+static void GRAPH_RDLOCK
+bdrv_register_buf_rollback(BlockDriverState *bs, void *host, size_t size,
+ BdrvChild *final_child)
{
BdrvChild *child;
+ GLOBAL_STATE_CODE();
+ assert_bdrv_graph_readable();
+
QLIST_FOREACH(child, &bs->children, next) {
if (child == final_child) {
break;
@@ -3213,6 +3215,8 @@ bool bdrv_register_buf(BlockDriverState *bs, void *host, size_t size,
BdrvChild *child;
GLOBAL_STATE_CODE();
+ GRAPH_RDLOCK_GUARD_MAINLOOP();
+
if (bs->drv && bs->drv->bdrv_register_buf) {
if (!bs->drv->bdrv_register_buf(bs, host, size, errp)) {
return false;
@@ -3232,6 +3236,8 @@ void bdrv_unregister_buf(BlockDriverState *bs, void *host, size_t size)
BdrvChild *child;
GLOBAL_STATE_CODE();
+ GRAPH_RDLOCK_GUARD_MAINLOOP();
+
if (bs->drv && bs->drv->bdrv_unregister_buf) {
bs->drv->bdrv_unregister_buf(bs, host, size);
}
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
index 30e6bd4..88d9897 100644
--- a/include/block/block_int-common.h
+++ b/include/block/block_int-common.h
@@ -445,9 +445,10 @@ struct BlockDriver {
*
* Returns: true on success, false on failure
*/
- bool (*bdrv_register_buf)(BlockDriverState *bs, void *host, size_t size,
- Error **errp);
- void (*bdrv_unregister_buf)(BlockDriverState *bs, void *host, size_t size);
+ bool GRAPH_RDLOCK_PTR (*bdrv_register_buf)(
+ BlockDriverState *bs, void *host, size_t size, Error **errp);
+ void GRAPH_RDLOCK_PTR (*bdrv_unregister_buf)(
+ BlockDriverState *bs, void *host, size_t size);
/*
* This field is modified only under the BQL, and is part of