From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPN8Q-0005j0-96 for qemu-devel@nongnu.org; Wed, 03 Sep 2014 22:51:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPN8K-0006Jx-8E for qemu-devel@nongnu.org; Wed, 03 Sep 2014 22:50:54 -0400 Received: from mail-pd0-f177.google.com ([209.85.192.177]:50855) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPN8K-0006Jk-0l for qemu-devel@nongnu.org; Wed, 03 Sep 2014 22:50:48 -0400 Received: by mail-pd0-f177.google.com with SMTP id r10so12523104pdi.36 for ; Wed, 03 Sep 2014 19:50:47 -0700 (PDT) From: Ming Lei Date: Thu, 4 Sep 2014 10:50:26 +0800 Message-Id: <1409799028-24761-3-git-send-email-ming.lei@canonical.com> In-Reply-To: <1409799028-24761-1-git-send-email-ming.lei@canonical.com> References: <1409799028-24761-1-git-send-email-ming.lei@canonical.com> Subject: [Qemu-devel] [PATCH v1 2/4] linux-aio: handling -EAGAIN for !s->io_q.plugged case List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Peter Maydell , Paolo Bonzini , Stefan Hajnoczi , Kevin Wolf Cc: Ming Lei Previously -EAGAIN is simply ignored for !s->io_q.plugged case, and sometimes it is easy to cause -EIO to VM, such as NVME device. This patch handles -EAGAIN by io queue for !s->io_q.plugged case, and it will be retried in following aio completion cb. Suggested-by: Paolo Bonzini Signed-off-by: Ming Lei --- block/linux-aio.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/block/linux-aio.c b/block/linux-aio.c index ff66d1e..a979331 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -275,6 +275,11 @@ static int ioq_enqueue(struct qemu_laio_state *s, struct iocb *iocb) s->io_q.iocbs[idx++] = iocb; s->io_q.idx = idx; + /* don't submit until next completion for -EAGAIN of non plug case */ + if (unlikely(!s->io_q.plugged)) { + return 0; + } + /* submit immediately if queue depth is above 2/3 */ if (idx > s->io_q.size * 2 / 3) { return ioq_submit(s, true); @@ -342,10 +347,25 @@ BlockDriverAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd, io_set_eventfd(&laiocb->iocb, event_notifier_get_fd(&s->e)); if (!s->io_q.plugged) { - if (io_submit(s->ctx, 1, &iocbs) < 0) { + int ret; + + if (!s->io_q.idx) { + ret = io_submit(s->ctx, 1, &iocbs); + } else { + ret = -EAGAIN; + } + /* + * Switch to queue mode until -EAGAIN is handled, we suppose + * there is always uncompleted I/O, so try to enqueue it first, + * and will be submitted again in following aio completion cb. + */ + if (ret == -EAGAIN) { + goto enqueue; + } else if (ret < 0) { goto out_free_aiocb; } } else { + enqueue: if (ioq_enqueue(s, iocbs) < 0) { goto out_free_aiocb; } -- 1.7.9.5