[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v2 17/25] include/block/transactions: global state API + asse
From: |
Emanuele Giuseppe Esposito |
Subject: |
[RFC PATCH v2 17/25] include/block/transactions: global state API + assertions |
Date: |
Tue, 5 Oct 2021 10:32:07 -0400 |
transactions run always under the BQL lock, so they are all
in the global state API.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
include/qemu/transactions.h | 24 ++++++++++++++++++++++++
util/transactions.c | 4 ++++
2 files changed, 28 insertions(+)
diff --git a/include/qemu/transactions.h b/include/qemu/transactions.h
index 92c5965235..f4a7c473fa 100644
--- a/include/qemu/transactions.h
+++ b/include/qemu/transactions.h
@@ -37,6 +37,29 @@
#define QEMU_TRANSACTIONS_H
#include <gmodule.h>
+#include "qemu/main-loop.h"
+
+/*
+ * 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 and function pointers in this header must use
+ * this assertion:
+ * g_assert(qemu_in_main_thread());
+ * to catch when they are accidentally called without the BQL.
+ */
typedef struct TransactionActionDrv {
void (*abort)(void *opaque);
@@ -53,6 +76,7 @@ void tran_commit(Transaction *tran);
static inline void tran_finalize(Transaction *tran, int ret)
{
+ g_assert(qemu_in_main_thread());
if (ret < 0) {
tran_abort(tran);
} else {
diff --git a/util/transactions.c b/util/transactions.c
index d0bc9a3e73..20c3dafdb8 100644
--- a/util/transactions.c
+++ b/util/transactions.c
@@ -23,6 +23,7 @@
#include "qemu/osdep.h"
#include "qemu/transactions.h"
+#include "qemu/main-loop.h"
#include "qemu/queue.h"
typedef struct TransactionAction {
@@ -47,6 +48,7 @@ Transaction *tran_new(void)
void tran_add(Transaction *tran, TransactionActionDrv *drv, void *opaque)
{
TransactionAction *act;
+ g_assert(qemu_in_main_thread());
act = g_new(TransactionAction, 1);
*act = (TransactionAction) {
@@ -60,6 +62,7 @@ void tran_add(Transaction *tran, TransactionActionDrv *drv,
void *opaque)
void tran_abort(Transaction *tran)
{
TransactionAction *act, *next;
+ g_assert(qemu_in_main_thread());
QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) {
if (act->drv->abort) {
@@ -79,6 +82,7 @@ void tran_abort(Transaction *tran)
void tran_commit(Transaction *tran)
{
TransactionAction *act, *next;
+ g_assert(qemu_in_main_thread());
QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) {
if (act->drv->commit) {
--
2.27.0
- Re: [RFC PATCH v2 11/25] include/block/blockjob.h: global state API, (continued)
- [RFC PATCH v2 14/25] assertions for blockdev.h global state API, Emanuele Giuseppe Esposito, 2021/10/05
- [RFC PATCH v2 16/25] block/backup-top.h: global state API + assertions, Emanuele Giuseppe Esposito, 2021/10/05
- [RFC PATCH v2 18/25] block/coroutines: I/O API, Emanuele Giuseppe Esposito, 2021/10/05
- [RFC PATCH v2 17/25] include/block/transactions: global state API + assertions,
Emanuele Giuseppe Esposito <=
- [RFC PATCH v2 15/25] include/block/snapshot: global state API + assertions, Emanuele Giuseppe Esposito, 2021/10/05
- [RFC PATCH v2 19/25] block_int-common.h: split function pointers in BlockDriver, Emanuele Giuseppe Esposito, 2021/10/05
- [RFC PATCH v2 20/25] block_int-common.h: assertion in the callers of BlockDriver function pointers, Emanuele Giuseppe Esposito, 2021/10/05
- [RFC PATCH v2 21/25] block_int-common.h: split function pointers in BdrvChildClass, Emanuele Giuseppe Esposito, 2021/10/05