blockdev functions run always under the BQL lock. Signed-off-by: Emanuele Giuseppe Esposito <eespo...@redhat.com> --- include/sysemu/blockdev.h | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-)
diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index 32c2d6023c..28233f6b63 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -38,24 +38,49 @@ struct DriveInfo { QTAILQ_ENTRY(DriveInfo) next; }; -DriveInfo *blk_legacy_dinfo(BlockBackend *blk); +/* + * Global state (GS) API. These functions run under the BQL lock. + * + * If a function modifies the graph, it also uses drain and/or + * aio_context_acquire/release to be sure it has unique access. + * aio_context locking is needed together with BQL because of + * the thread-safe I/O API that concurrently runs and accesses + * the graph without the BQL. + * + * It is important to note that not all of these functions are + * necessarily limited to running under the BQL, but they would + * require additional auditing and may small thread-safety changes + * to move them into the I/O API. Often it's not worth doing that + * work since the APIs are only used with the BQL held at the + * moment, so they have been placed in the GS API (for now). + * + * All functions in this header must use this assertion: + * g_assert(qemu_in_main_thread()); + * to catch when they are accidentally called without the BQL. + */ + DriveInfo *blk_set_legacy_dinfo(BlockBackend *blk, DriveInfo *dinfo); BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo); void override_max_devs(BlockInterfaceType type, int max_devs); DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit); -void drive_mark_claimed_by_board(void); void drive_check_orphaned(void); DriveInfo *drive_get_by_index(BlockInterfaceType type, int index); int drive_get_max_bus(BlockInterfaceType type); -int drive_get_max_devs(BlockInterfaceType type); DriveInfo *drive_get_next(BlockInterfaceType type); +DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type, + Error **errp); + +/* Common functions that are neither I/O nor Global State */ + +DriveInfo *blk_legacy_dinfo(BlockBackend *blk); +int drive_get_max_devs(BlockInterfaceType type); + QemuOpts *drive_def(const char *optstr); + QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file, const char *optstr); -DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type, - Error **errp); #endif -- 2.27.0