[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 20/23] block: Mark bdrv_(un)register_buf() GRAPH_RDLOCK
From: |
Kevin Wolf |
Subject: |
[PATCH 20/23] block: Mark bdrv_(un)register_buf() GRAPH_RDLOCK |
Date: |
Fri, 3 Feb 2023 16:21:59 +0100 |
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>
---
include/block/block_int-common.h | 7 ++++---
block/io.c | 14 ++++++++++----
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
index 30e6bd4909..88d9897c97 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
diff --git a/block/io.c b/block/io.c
index be350aba98..9d3db1753d 100644
--- a/block/io.c
+++ b/block/io.c
@@ -3184,13 +3184,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;
@@ -3210,6 +3212,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;
@@ -3229,6 +3233,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);
}
--
2.38.1
- [PATCH 07/23] block: Mark bdrv_co_flush() and callers GRAPH_RDLOCK, (continued)
- [PATCH 07/23] block: Mark bdrv_co_flush() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- [PATCH 11/23] block: Mark public read/write functions GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- [PATCH 13/23] block: Mark bdrv_co_do_pwrite_zeroes() GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- [PATCH 14/23] block: Mark bdrv_co_copy_range() GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- [PATCH 15/23] block: Mark preadv_snapshot/snapshot_block_status GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- [PATCH 18/23] block: Mark bdrv_co_is_inserted() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- [PATCH 17/23] block: Mark bdrv_co_io_(un)plug() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- [PATCH 19/23] block: Mark bdrv_co_eject/lock_medium() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- [PATCH 16/23] block: Mark bdrv_co_create() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- [PATCH 21/23] block: Mark bdrv_co_delete_file() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- [PATCH 20/23] block: Mark bdrv_(un)register_buf() GRAPH_RDLOCK,
Kevin Wolf <=
- [PATCH 23/23] block: Mark bdrv_co_refresh_total_sectors() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- [PATCH 22/23] block: Mark bdrv_*_dirty_bitmap() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/02/03
- Re: [PATCH 00/23] block: Lock the graph, part 2 (BlockDriver callbacks), Emanuele Giuseppe Esposito, 2023/02/17
- Re: [PATCH 00/23] block: Lock the graph, part 2 (BlockDriver callbacks), Stefan Hajnoczi, 2023/02/21