From patchwork Thu Aug 21 11:56:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 381934 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 782A714009C for ; Thu, 21 Aug 2014 21:59:20 +1000 (EST) Received: from localhost ([::1]:60139 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKR1S-0005Xm-MM for incoming@patchwork.ozlabs.org; Thu, 21 Aug 2014 07:59:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKQzC-0001A8-L5 for qemu-devel@nongnu.org; Thu, 21 Aug 2014 07:57:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XKQz6-0006Ad-Gi for qemu-devel@nongnu.org; Thu, 21 Aug 2014 07:56:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14474) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKQz6-00069s-8R for qemu-devel@nongnu.org; Thu, 21 Aug 2014 07:56:52 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7LBupUO006125 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 21 Aug 2014 07:56:51 -0400 Received: from T430.nay.redhat.com (dhcp-14-155.nay.redhat.com [10.66.14.155]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7LBudxT001979; Thu, 21 Aug 2014 07:56:49 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 21 Aug 2014 19:56:51 +0800 Message-Id: <1408622216-9578-5-git-send-email-famz@redhat.com> In-Reply-To: <1408622216-9578-1-git-send-email-famz@redhat.com> References: <1408622216-9578-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi Subject: [Qemu-devel] [RFC PATCH 4/9] linux-aio: Implement .cancel_async 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 Just call io_cancel (2), if it fails, it means the request is not canceled, so the event loop will eventually call qemu_laio_process_completion. In qemu_laio_process_completion, change to call the cb unconditionally. It is required by .cancel_async, and also acceptable by .cancel. Signed-off-by: Fam Zheng --- block/linux-aio.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/block/linux-aio.c b/block/linux-aio.c index 7ac7e8c..adf3b2e 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -79,9 +79,8 @@ static void qemu_laio_process_completion(struct qemu_laio_state *s, ret = -EINVAL; } } - - laiocb->common.cb(laiocb->common.opaque, ret); } + laiocb->common.cb(laiocb->common.opaque, ret); qemu_aio_release(laiocb); } @@ -110,6 +109,22 @@ static void qemu_laio_completion_cb(EventNotifier *e) } } +static void laio_cancel_async(BlockDriverAIOCB *blockacb) +{ + struct qemu_laiocb *laiocb = (struct qemu_laiocb *)blockacb; + struct io_event event; + int ret; + + ret = io_cancel(laiocb->ctx->ctx, &laiocb->iocb, &event); + laiocb->ret = -ECANCELED; + if (!ret) { + /* iocb is not cancelled, cb will be called by the event loop later */ + return; + } + + laiocb->common.cb(laiocb->common.opaque, laiocb->ret); +} + static void laio_cancel(BlockDriverAIOCB *blockacb) { struct qemu_laiocb *laiocb = (struct qemu_laiocb *)blockacb; @@ -145,6 +160,7 @@ static void laio_cancel(BlockDriverAIOCB *blockacb) static const AIOCBInfo laio_aiocb_info = { .aiocb_size = sizeof(struct qemu_laiocb), .cancel = laio_cancel, + .cancel_async = laio_cancel_async, }; static void ioq_init(LaioQueue *io_q)