@@ -1438,7 +1438,7 @@ static bool bdrv_child_cb_attach(BdrvChild *child)
{
BlockDriverState *bs = child->opaque;
- assert_bdrv_graph_writable(bs);
+ assert_bdrv_graph_writable();
QLIST_INSERT_HEAD(&bs->children, child, next);
/* Paired with bdrv_graph_wrlock() in bdrv_replace_child_noperm */
@@ -1466,7 +1466,7 @@ static bool bdrv_child_cb_detach(BdrvChild *child)
/* Paired with bdrv_graph_wrunlock() in bdrv_replace_child_noperm */
bdrv_graph_wrlock();
- assert_bdrv_graph_writable(bs);
+ assert_bdrv_graph_writable();
QLIST_REMOVE(child, next);
return true;
@@ -2885,7 +2885,7 @@ static void bdrv_replace_child_noperm(BdrvChild **childp,
bdrv_graph_wrlock();
}
locked = true;
- assert_bdrv_graph_writable(old_bs);
+ assert_bdrv_graph_writable();
QLIST_REMOVE(child, next_parent);
}
@@ -2899,7 +2899,7 @@ static void bdrv_replace_child_noperm(BdrvChild **childp,
bdrv_graph_wrlock();
locked = true;
}
- assert_bdrv_graph_writable(new_bs);
+ assert_bdrv_graph_writable();
QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent);
/*
@@ -214,3 +214,14 @@ void coroutine_fn bdrv_graph_co_rdunlock(void)
aio_wait_kick();
}
}
+
+void assert_bdrv_graph_readable(void)
+{
+ assert(qemu_in_main_thread() || reader_count());
+}
+
+void assert_bdrv_graph_writable(void)
+{
+ assert(qemu_in_main_thread());
+ assert(qatomic_read(&has_writer));
+}
@@ -309,21 +309,4 @@ void bdrv_remove_aio_context_notifier(BlockDriverState *bs,
*/
void bdrv_drain_all_end_quiesce(BlockDriverState *bs);
-/**
- * Make sure that the function is running under both drain and BQL.
- * The latter protects from concurrent writings
- * from the GS API, while the former prevents concurrent reads
- * from I/O.
- */
-static inline void assert_bdrv_graph_writable(BlockDriverState *bs)
-{
- /*
- * TODO: this function is incomplete. Because the users of this
- * assert lack the necessary drains, check only for BQL.
- * Once the necessary drains are added,
- * assert also for qatomic_read(&bs->quiesce_counter) > 0
- */
- assert(qemu_in_main_thread());
-}
-
#endif /* BLOCK_INT_GLOBAL_STATE */
@@ -52,5 +52,20 @@ void coroutine_fn bdrv_graph_co_rdlock(void);
*/
void coroutine_fn bdrv_graph_co_rdunlock(void);
+/*
+ * assert_bdrv_graph_readable:
+ * Make sure that the reader is either the main loop,
+ * or there is at least a reader helding the rdlock.
+ * In this way an incoming writer is aware of the read and waits.
+ */
+void assert_bdrv_graph_readable(void);
+
+/*
+ * assert_bdrv_graph_writable:
+ * Make sure that the writer is the main loop and has set @has_writer,
+ * so that incoming readers will pause.
+ */
+void assert_bdrv_graph_writable(void);
+
#endif /* BLOCK_LOCK_H */
Remove the old assert_bdrv_graph_writable, and replace it with the new version using graph-lock API. See the function documentation for more information. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> --- block.c | 8 ++++---- block/graph-lock.c | 11 +++++++++++ include/block/block_int-global-state.h | 17 ----------------- include/block/graph-lock.h | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 21 deletions(-)