|
18 | 18 | #include "qapi/error.h" |
19 | 19 | #include "trace.h" |
20 | 20 |
|
| 21 | +/* Only used for assertions. */ |
| 22 | +#include "qemu/coroutine_int.h" |
| 23 | + |
21 | 24 | /* io_uring ring size */ |
22 | 25 | #define MAX_ENTRIES 128 |
23 | 26 |
|
@@ -50,10 +53,9 @@ typedef struct LuringState { |
50 | 53 |
|
51 | 54 | struct io_uring ring; |
52 | 55 |
|
53 | | - /* io queue for submit at batch. Protected by AioContext lock. */ |
| 56 | + /* No locking required, only accessed from AioContext home thread */ |
54 | 57 | LuringQueue io_q; |
55 | 58 |
|
56 | | - /* I/O completion processing. Only runs in I/O thread. */ |
57 | 59 | QEMUBH *completion_bh; |
58 | 60 | } LuringState; |
59 | 61 |
|
@@ -209,6 +211,7 @@ static void luring_process_completions(LuringState *s) |
209 | 211 | * eventually runs later. Coroutines cannot be entered recursively |
210 | 212 | * so avoid doing that! |
211 | 213 | */ |
| 214 | + assert(luringcb->co->ctx == s->aio_context); |
212 | 215 | if (!qemu_coroutine_entered(luringcb->co)) { |
213 | 216 | aio_co_wake(luringcb->co); |
214 | 217 | } |
@@ -262,13 +265,11 @@ static int ioq_submit(LuringState *s) |
262 | 265 |
|
263 | 266 | static void luring_process_completions_and_submit(LuringState *s) |
264 | 267 | { |
265 | | - aio_context_acquire(s->aio_context); |
266 | 268 | luring_process_completions(s); |
267 | 269 |
|
268 | 270 | if (!s->io_q.plugged && s->io_q.in_queue > 0) { |
269 | 271 | ioq_submit(s); |
270 | 272 | } |
271 | | - aio_context_release(s->aio_context); |
272 | 273 | } |
273 | 274 |
|
274 | 275 | static void qemu_luring_completion_bh(void *opaque) |
@@ -306,14 +307,18 @@ static void ioq_init(LuringQueue *io_q) |
306 | 307 | io_q->blocked = false; |
307 | 308 | } |
308 | 309 |
|
309 | | -void luring_io_plug(BlockDriverState *bs, LuringState *s) |
| 310 | +void luring_io_plug(void) |
310 | 311 | { |
| 312 | + AioContext *ctx = qemu_get_current_aio_context(); |
| 313 | + LuringState *s = aio_get_linux_io_uring(ctx); |
311 | 314 | trace_luring_io_plug(s); |
312 | 315 | s->io_q.plugged++; |
313 | 316 | } |
314 | 317 |
|
315 | | -void luring_io_unplug(BlockDriverState *bs, LuringState *s) |
| 318 | +void luring_io_unplug(void) |
316 | 319 | { |
| 320 | + AioContext *ctx = qemu_get_current_aio_context(); |
| 321 | + LuringState *s = aio_get_linux_io_uring(ctx); |
317 | 322 | assert(s->io_q.plugged); |
318 | 323 | trace_luring_io_unplug(s, s->io_q.blocked, s->io_q.plugged, |
319 | 324 | s->io_q.in_queue, s->io_q.in_flight); |
@@ -373,10 +378,12 @@ static int luring_do_submit(int fd, LuringAIOCB *luringcb, LuringState *s, |
373 | 378 | return 0; |
374 | 379 | } |
375 | 380 |
|
376 | | -int coroutine_fn luring_co_submit(BlockDriverState *bs, LuringState *s, int fd, |
377 | | - uint64_t offset, QEMUIOVector *qiov, int type) |
| 381 | +int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t offset, |
| 382 | + QEMUIOVector *qiov, int type) |
378 | 383 | { |
379 | 384 | int ret; |
| 385 | + AioContext *ctx = qemu_get_current_aio_context(); |
| 386 | + LuringState *s = aio_get_linux_io_uring(ctx); |
380 | 387 | LuringAIOCB luringcb = { |
381 | 388 | .co = qemu_coroutine_self(), |
382 | 389 | .ret = -EINPROGRESS, |
|
0 commit comments