Avoid including all of qdev everywhere (the hw/core/qdev.h header in fact
brings in a lot more headers too), instead declare a couple structs for
which only a pointer type is needed.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/block/aio.h | 7 +++----
include/block/block-copy.h | 1 +
include/block/block-global-state.h | 1 +
include/block/block-io.h | 1 +
include/block/dirty-bitmap.h | 1 +
include/hw/core/qdev.h | 6 +-----
include/qemu/job.h | 1 +
include/qemu/main-loop.h | 2 +-
include/qemu/mem-reentrancy.h | 10 ++++++++++
net/net.c | 1 +
util/async.c | 1 +
11 files changed, 22 insertions(+), 10 deletions(-)
create mode 100644 include/qemu/mem-reentrancy.h
diff --git a/include/block/aio.h b/include/block/aio.h
index 59c56d695ee..8cca2360d1a 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -23,9 +23,8 @@
#include "qemu/lockcnt.h"
#include "qemu/thread.h"
#include "qemu/timer.h"
-#include "block/graph-lock.h"
-#include "hw/core/qdev.h"
+struct MemReentrancyGuard;
typedef struct AioHandler AioHandler;
typedef QLIST_HEAD(, AioHandler) AioHandlerList;
@@ -211,7 +210,7 @@ struct AioContext {
* of nodes and edges from block graph while some
* other thread is traversing it.
*/
- BdrvGraphRWlock *bdrv_graph;
+ struct BdrvGraphRWlock *bdrv_graph;
/* The list of registered AIO handlers. Protected by ctx->list_lock. */
AioHandlerList aio_handlers;
@@ -393,7 +392,7 @@ void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
* device-reentrancy issues
*/
QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
- const char *name, MemReentrancyGuard *reentrancy_guard);
+ const char *name, struct MemReentrancyGuard *reentrancy_guard);
/**
* aio_bh_new: Allocate a new bottom half structure
diff --git a/include/block/block-copy.h b/include/block/block-copy.h
index dd5cc82f3b2..0df2771181b 100644
--- a/include/block/block-copy.h
+++ b/include/block/block-copy.h
@@ -16,6 +16,7 @@
#define BLOCK_COPY_H
#include "block/block-common.h"
+#include "block/graph-lock.h"
#include "qemu/progress_meter.h"
/* All APIs are thread-safe */
diff --git a/include/block/block-global-state.h b/include/block/block-global-state.h
index c2127f17249..ed89999f0fb 100644
--- a/include/block/block-global-state.h
+++ b/include/block/block-global-state.h
@@ -25,6 +25,7 @@
#define BLOCK_GLOBAL_STATE_H
#include "qemu/aiocb.h"
+#include "block/graph-lock.h"
#include "block/block-common.h"
#include "qemu/coroutine.h"
#include "qemu/transactions.h"
diff --git a/include/block/block-io.h b/include/block/block-io.h
index e5efe0efb2f..7925e2241e6 100644
--- a/include/block/block-io.h
+++ b/include/block/block-io.h
@@ -27,6 +27,7 @@
#include "qemu/aiocb.h"
#include "block/aio-wait.h"
#include "block/block-common.h"
+#include "block/graph-lock.h"
#include "qemu/coroutine.h"
#include "qemu/iov.h"
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
index fa956debfb2..28029bbc2bc 100644
--- a/include/block/dirty-bitmap.h
+++ b/include/block/dirty-bitmap.h
@@ -2,6 +2,7 @@
#define BLOCK_DIRTY_BITMAP_H
#include "block/block-common.h"
+#include "block/graph-lock.h"
#include "qapi/qapi-types-block-core.h"
#include "qemu/hbitmap.h"
diff --git a/include/hw/core/qdev.h b/include/hw/core/qdev.h
index e211d807e82..4b2730e9d8e 100644
--- a/include/hw/core/qdev.h
+++ b/include/hw/core/qdev.h
@@ -4,6 +4,7 @@
#include "qemu/atomic.h"
#include "qemu/queue.h"
#include "qemu/bitmap.h"
+#include "qemu/mem-reentrancy.h"
#include "qemu/rcu.h"
#include "qemu/rcu_queue.h"
#include "qom/object.h"
@@ -208,11 +209,6 @@ struct NamedClockList {
QLIST_ENTRY(NamedClockList) node;
};
-typedef struct MemReentrancyGuard {
- bool engaged_in_io;
-} MemReentrancyGuard;
-
-
typedef QLIST_HEAD(, NamedGPIOList) NamedGPIOListHead;
typedef QLIST_HEAD(, NamedClockList) NamedClockListHead;
typedef QLIST_HEAD(, BusState) BusStateHead;
diff --git a/include/qemu/job.h b/include/qemu/job.h
index af29b8c6531..2b163602c56 100644
--- a/include/qemu/job.h
+++ b/include/qemu/job.h
@@ -32,6 +32,7 @@
#include "qemu/progress_meter.h"
#include "qemu/coroutine.h"
#include "block/aio.h"
+#include "block/graph-lock.h"
typedef struct JobDriver JobDriver;
typedef struct JobTxn JobTxn;
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index 0d55c636b21..241dc87be50 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -431,7 +431,7 @@ void qemu_cond_timedwait_bql(QemuCond *cond, int ms);
#define qemu_bh_new(cb, opaque) \
qemu_bh_new_full((cb), (opaque), (stringify(cb)), NULL)
QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name,
- MemReentrancyGuard *reentrancy_guard);
+ struct MemReentrancyGuard *reentrancy_guard);
void qemu_bh_schedule_idle(QEMUBH *bh);
enum {
diff --git a/include/qemu/mem-reentrancy.h b/include/qemu/mem-reentrancy.h
new file mode 100644
index 00000000000..07cafd47179
--- /dev/null
+++ b/include/qemu/mem-reentrancy.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef QEMU_MEM_REENTRANCY_H
+#define QEMU_MEM_REENTRANCY_H 1
+
+typedef struct MemReentrancyGuard {
+ bool engaged_in_io;
+} MemReentrancyGuard;
+
+#endif
diff --git a/net/net.c b/net/net.c
index 4930b573ed3..a176936f9bc 100644
--- a/net/net.c
+++ b/net/net.c
@@ -39,6 +39,7 @@
#include "qobject/qdict.h"
#include "qapi/qmp/qerror.h"
#include "qemu/error-report.h"
+#include "qemu/mem-reentrancy.h"
#include "qemu/sockets.h"
#include "qemu/cutils.h"
#include "qemu/config-file.h"
diff --git a/util/async.c b/util/async.c
index 48f88286369..39f391fb71a 100644
--- a/util/async.c
+++ b/util/async.c
@@ -29,6 +29,7 @@
#include "block/thread-pool.h"
#include "block/graph-lock.h"
#include "qemu/main-loop.h"
+#include "qemu/mem-reentrancy.h"
#include "qemu/atomic.h"
#include "qemu/lockcnt.h"
#include "qemu/rcu_queue.h"
--
2.52.0
On 3/12/25 19:51, Paolo Bonzini wrote:
> Avoid including all of qdev everywhere (the hw/core/qdev.h header in fact
> brings in a lot more headers too), instead declare a couple structs for
> which only a pointer type is needed.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> include/block/aio.h | 7 +++----
> include/block/block-copy.h | 1 +
> include/block/block-global-state.h | 1 +
> include/block/block-io.h | 1 +
> include/block/dirty-bitmap.h | 1 +
> include/hw/core/qdev.h | 6 +-----
> include/qemu/job.h | 1 +
> include/qemu/main-loop.h | 2 +-
> include/qemu/mem-reentrancy.h | 10 ++++++++++
> net/net.c | 1 +
> util/async.c | 1 +
> 11 files changed, 22 insertions(+), 10 deletions(-)
> create mode 100644 include/qemu/mem-reentrancy.h
>
> diff --git a/include/block/aio.h b/include/block/aio.h
> index 59c56d695ee..8cca2360d1a 100644
> --- a/include/block/aio.h
> +++ b/include/block/aio.h
> @@ -23,9 +23,8 @@
> #include "qemu/lockcnt.h"
> #include "qemu/thread.h"
> #include "qemu/timer.h"
> -#include "block/graph-lock.h"
> -#include "hw/core/qdev.h"
>
> +struct MemReentrancyGuard;
>
> typedef struct AioHandler AioHandler;
> typedef QLIST_HEAD(, AioHandler) AioHandlerList;
> @@ -211,7 +210,7 @@ struct AioContext {
> * of nodes and edges from block graph while some
> * other thread is traversing it.
> */
> - BdrvGraphRWlock *bdrv_graph;
> + struct BdrvGraphRWlock *bdrv_graph;
>
> /* The list of registered AIO handlers. Protected by ctx->list_lock. */
> AioHandlerList aio_handlers;
> @@ -393,7 +392,7 @@ void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
> * device-reentrancy issues
> */
> QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
> - const char *name, MemReentrancyGuard *reentrancy_guard);
> + const char *name, struct MemReentrancyGuard *reentrancy_guard);
>
I suppose these changes were before you move the declarations to their
own "qemu/mem-reentrancy.h" header?
On 12/4/25 09:35, Philippe Mathieu-Daudé wrote:
> On 3/12/25 19:51, Paolo Bonzini wrote:
>> Avoid including all of qdev everywhere (the hw/core/qdev.h header in fact
>> brings in a lot more headers too), instead declare a couple structs for
>> which only a pointer type is needed.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>> include/block/aio.h | 7 +++----
>> include/block/block-copy.h | 1 +
>> include/block/block-global-state.h | 1 +
>> include/block/block-io.h | 1 +
>> include/block/dirty-bitmap.h | 1 +
>> include/hw/core/qdev.h | 6 +-----
>> include/qemu/job.h | 1 +
>> include/qemu/main-loop.h | 2 +-
>> include/qemu/mem-reentrancy.h | 10 ++++++++++
>> net/net.c | 1 +
>> util/async.c | 1 +
>> 11 files changed, 22 insertions(+), 10 deletions(-)
>> create mode 100644 include/qemu/mem-reentrancy.h
>>
>> diff --git a/include/block/aio.h b/include/block/aio.h
>> index 59c56d695ee..8cca2360d1a 100644
>> --- a/include/block/aio.h
>> +++ b/include/block/aio.h
>> @@ -23,9 +23,8 @@
>> #include "qemu/lockcnt.h"
>> #include "qemu/thread.h"
>> #include "qemu/timer.h"
>> -#include "block/graph-lock.h"
>> -#include "hw/core/qdev.h"
>> +struct MemReentrancyGuard;
>> typedef struct AioHandler AioHandler;
>> typedef QLIST_HEAD(, AioHandler) AioHandlerList;
>> @@ -211,7 +210,7 @@ struct AioContext {
>> * of nodes and edges from block graph while some
>> * other thread is traversing it.
>> */
>> - BdrvGraphRWlock *bdrv_graph;
>> + struct BdrvGraphRWlock *bdrv_graph;
>> /* The list of registered AIO handlers. Protected by ctx-
>> >list_lock. */
>> AioHandlerList aio_handlers;
>> @@ -393,7 +392,7 @@ void aio_bh_schedule_oneshot_full(AioContext *ctx,
>> QEMUBHFunc *cb, void *opaque,
>> * device-reentrancy issues
>> */
>> QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
>> - const char *name, MemReentrancyGuard
>> *reentrancy_guard);
>> + const char *name, struct MemReentrancyGuard
>> *reentrancy_guard);
>
> I suppose these changes were before you move the declarations to their
> own "qemu/mem-reentrancy.h" header?
Yes, but also qemu/mem-reentrancy.h is not included here.
Paolo
On 4/12/25 10:25, Paolo Bonzini wrote:
> On 12/4/25 09:35, Philippe Mathieu-Daudé wrote:
>> On 3/12/25 19:51, Paolo Bonzini wrote:
>>> Avoid including all of qdev everywhere (the hw/core/qdev.h header in
>>> fact
>>> brings in a lot more headers too), instead declare a couple structs for
>>> which only a pointer type is needed.
>>>
>>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>>> ---
>>> include/block/aio.h | 7 +++----
>>> include/block/block-copy.h | 1 +
>>> include/block/block-global-state.h | 1 +
>>> include/block/block-io.h | 1 +
>>> include/block/dirty-bitmap.h | 1 +
>>> include/hw/core/qdev.h | 6 +-----
>>> include/qemu/job.h | 1 +
>>> include/qemu/main-loop.h | 2 +-
>>> include/qemu/mem-reentrancy.h | 10 ++++++++++
>>> net/net.c | 1 +
>>> util/async.c | 1 +
>>> 11 files changed, 22 insertions(+), 10 deletions(-)
>>> create mode 100644 include/qemu/mem-reentrancy.h
>>>
>>> diff --git a/include/block/aio.h b/include/block/aio.h
>>> index 59c56d695ee..8cca2360d1a 100644
>>> --- a/include/block/aio.h
>>> +++ b/include/block/aio.h
>>> @@ -23,9 +23,8 @@
>>> #include "qemu/lockcnt.h"
>>> #include "qemu/thread.h"
>>> #include "qemu/timer.h"
>>> -#include "block/graph-lock.h"
>>> -#include "hw/core/qdev.h"
>>> +struct MemReentrancyGuard;
>>> typedef struct AioHandler AioHandler;
>>> typedef QLIST_HEAD(, AioHandler) AioHandlerList;
>>> @@ -211,7 +210,7 @@ struct AioContext {
>>> * of nodes and edges from block graph while some
>>> * other thread is traversing it.
>>> */
>>> - BdrvGraphRWlock *bdrv_graph;
>>> + struct BdrvGraphRWlock *bdrv_graph;
>>> /* The list of registered AIO handlers. Protected by ctx-
>>> >list_lock. */
>>> AioHandlerList aio_handlers;
>>> @@ -393,7 +392,7 @@ void aio_bh_schedule_oneshot_full(AioContext
>>> *ctx, QEMUBHFunc *cb, void *opaque,
>>> * device-reentrancy issues
>>> */
>>> QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
>>> - const char *name, MemReentrancyGuard
>>> *reentrancy_guard);
>>> + const char *name, struct MemReentrancyGuard
>>> *reentrancy_guard);
>>
>> I suppose these changes were before you move the declarations to their
>> own "qemu/mem-reentrancy.h" header?
>
> Yes, but also qemu/mem-reentrancy.h is not included here.
We want to also include it instead, right? (No need to forward declare)
On 12/4/25 18:03, Philippe Mathieu-Daudé wrote: >>>> QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void >>>> *opaque, >>>> - const char *name, MemReentrancyGuard >>>> *reentrancy_guard); >>>> + const char *name, struct MemReentrancyGuard >>>> *reentrancy_guard); >>> >>> I suppose these changes were before you move the declarations to their >>> own "qemu/mem-reentrancy.h" header? >> >> Yes, but also qemu/mem-reentrancy.h is not included here. > > We want to also include it instead, right? (No need to forward declare) Why? The struct is opaque, and as a general principle avoiding header-from-header inclusions reduces compile times. Paolo
© 2016 - 2025 Red Hat, Inc.