|
@@ -54,10 +54,10 @@ struct LinuxAioState {
|
|
io_context_t ctx;
|
|
io_context_t ctx;
|
|
EventNotifier e;
|
|
EventNotifier e;
|
|
|
|
|
|
- /* io queue for submit at batch */
|
|
|
|
|
|
+ /* io queue for submit at batch. Protected by AioContext lock. */
|
|
LaioQueue io_q;
|
|
LaioQueue io_q;
|
|
|
|
|
|
- /* I/O completion processing */
|
|
|
|
|
|
+ /* I/O completion processing. Only runs in I/O thread. */
|
|
QEMUBH *completion_bh;
|
|
QEMUBH *completion_bh;
|
|
int event_idx;
|
|
int event_idx;
|
|
int event_max;
|
|
int event_max;
|
|
@@ -75,6 +75,7 @@ static inline ssize_t io_event_ret(struct io_event *ev)
|
|
*/
|
|
*/
|
|
static void qemu_laio_process_completion(struct qemu_laiocb *laiocb)
|
|
static void qemu_laio_process_completion(struct qemu_laiocb *laiocb)
|
|
{
|
|
{
|
|
|
|
+ LinuxAioState *s = laiocb->ctx;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
ret = laiocb->ret;
|
|
ret = laiocb->ret;
|
|
@@ -93,6 +94,7 @@ static void qemu_laio_process_completion(struct qemu_laiocb *laiocb)
|
|
}
|
|
}
|
|
|
|
|
|
laiocb->ret = ret;
|
|
laiocb->ret = ret;
|
|
|
|
+ aio_context_acquire(s->aio_context);
|
|
if (laiocb->co) {
|
|
if (laiocb->co) {
|
|
/* If the coroutine is already entered it must be in ioq_submit() and
|
|
/* If the coroutine is already entered it must be in ioq_submit() and
|
|
* will notice laio->ret has been filled in when it eventually runs
|
|
* will notice laio->ret has been filled in when it eventually runs
|
|
@@ -106,6 +108,7 @@ static void qemu_laio_process_completion(struct qemu_laiocb *laiocb)
|
|
laiocb->common.cb(laiocb->common.opaque, ret);
|
|
laiocb->common.cb(laiocb->common.opaque, ret);
|
|
qemu_aio_unref(laiocb);
|
|
qemu_aio_unref(laiocb);
|
|
}
|
|
}
|
|
|
|
+ aio_context_release(s->aio_context);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -234,9 +237,12 @@ static void qemu_laio_process_completions(LinuxAioState *s)
|
|
static void qemu_laio_process_completions_and_submit(LinuxAioState *s)
|
|
static void qemu_laio_process_completions_and_submit(LinuxAioState *s)
|
|
{
|
|
{
|
|
qemu_laio_process_completions(s);
|
|
qemu_laio_process_completions(s);
|
|
|
|
+
|
|
|
|
+ aio_context_acquire(s->aio_context);
|
|
if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) {
|
|
if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) {
|
|
ioq_submit(s);
|
|
ioq_submit(s);
|
|
}
|
|
}
|
|
|
|
+ aio_context_release(s->aio_context);
|
|
}
|
|
}
|
|
|
|
|
|
static void qemu_laio_completion_bh(void *opaque)
|
|
static void qemu_laio_completion_bh(void *opaque)
|
|
@@ -251,9 +257,7 @@ static void qemu_laio_completion_cb(EventNotifier *e)
|
|
LinuxAioState *s = container_of(e, LinuxAioState, e);
|
|
LinuxAioState *s = container_of(e, LinuxAioState, e);
|
|
|
|
|
|
if (event_notifier_test_and_clear(&s->e)) {
|
|
if (event_notifier_test_and_clear(&s->e)) {
|
|
- aio_context_acquire(s->aio_context);
|
|
|
|
qemu_laio_process_completions_and_submit(s);
|
|
qemu_laio_process_completions_and_submit(s);
|
|
- aio_context_release(s->aio_context);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -267,9 +271,7 @@ static bool qemu_laio_poll_cb(void *opaque)
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- aio_context_acquire(s->aio_context);
|
|
|
|
qemu_laio_process_completions_and_submit(s);
|
|
qemu_laio_process_completions_and_submit(s);
|
|
- aio_context_release(s->aio_context);
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -459,6 +461,7 @@ void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context)
|
|
{
|
|
{
|
|
aio_set_event_notifier(old_context, &s->e, false, NULL, NULL);
|
|
aio_set_event_notifier(old_context, &s->e, false, NULL, NULL);
|
|
qemu_bh_delete(s->completion_bh);
|
|
qemu_bh_delete(s->completion_bh);
|
|
|
|
+ s->aio_context = NULL;
|
|
}
|
|
}
|
|
|
|
|
|
void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context)
|
|
void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context)
|