From patchwork Thu Sep 4 02:50:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 385716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DDAE31400E9 for ; Thu, 4 Sep 2014 12:53:51 +1000 (EST) Received: from localhost ([::1]:48549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPNBG-0001HY-36 for incoming@patchwork.ozlabs.org; Wed, 03 Sep 2014 22:53:50 -0400 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) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qlwL/7m7Nen3f0uLeRaFhpwHO7Ng+gCiymG9H0J41v0=; b=eVm6WuujZjm0KP6duXlqtuyuHmHffcFPMONigV/nvuI4r1UvlYn3L9cuvwWDYpKGHI geIfLeR5Hj9EAb4HksGHMASSjncJsKHea5BB9wuPsHZGnodqQRn1gYowO8FTwyiBMs4E qXXoc2QaWpBOY1U7NbUjnJGL/XcHQdCakYLJsdtxovsMMYIRBt4w+0coaXiCh7BDlWU6 hvg3HQP09ftX+dTOSgcpjknrafslbcNTM+bcaCYb6Wa+25tvFfc1wqAniOBPaYYEPQNn uqSNkbA+GBG/sjOmkWW4OXpJrR/6DfmjZovrmyfbZ3LW3Af7poeXE1g0C9ztAIhNZk9B Ah6g== X-Received: by 10.66.122.99 with SMTP id lr3mr3258512pab.0.1409799047042; Wed, 03 Sep 2014 19:50:47 -0700 (PDT) Received: from localhost ([183.14.17.164]) by mx.google.com with ESMTPSA id hp1sm221995pbb.77.2014.09.03.19.50.45 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 03 Sep 2014 19:50:46 -0700 (PDT) From: Ming Lei To: qemu-devel@nongnu.org, Peter Maydell , Paolo Bonzini , Stefan Hajnoczi , Kevin Wolf Date: Thu, 4 Sep 2014 10:50:26 +0800 Message-Id: <1409799028-24761-3-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1409799028-24761-1-git-send-email-ming.lei@canonical.com> References: <1409799028-24761-1-git-send-email-ming.lei@canonical.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.177 Cc: Ming Lei Subject: [Qemu-devel] [PATCH v1 2/4] linux-aio: handling -EAGAIN for !s->io_q.plugged case X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; }