From patchwork Tue Mar 29 12:13:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MORITA Kazutaka X-Patchwork-Id: 88754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 87D3CB6F14 for ; Tue, 29 Mar 2011 23:20:47 +1100 (EST) Received: from localhost ([127.0.0.1]:51905 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q4Xtm-0007vv-TW for incoming@patchwork.ozlabs.org; Tue, 29 Mar 2011 08:19:50 -0400 Received: from [140.186.70.92] (port=48860 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q4XpU-0004fv-MH for qemu-devel@nongnu.org; Tue, 29 Mar 2011 08:15:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q4XpP-0001US-Me for qemu-devel@nongnu.org; Tue, 29 Mar 2011 08:15:24 -0400 Received: from sh.osrg.net ([192.16.179.4]:33310) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q4XpP-0001Rw-7t for qemu-devel@nongnu.org; Tue, 29 Mar 2011 08:15:19 -0400 Received: from fs.osrg.net (postfix@fs.osrg.net [10.0.0.12]) by sh.osrg.net (8.14.3/8.14.3/OSRG-NET) with ESMTP id p2TCEpAE009289; Tue, 29 Mar 2011 21:14:52 +0900 Received: from localhost (dfs1401.osrg.net [10.68.14.1]) by fs.osrg.net (Postfix) with ESMTP id C45403E02E7; Tue, 29 Mar 2011 21:14:51 +0900 (JST) From: MORITA Kazutaka To: kwolf@redhat.com Date: Tue, 29 Mar 2011 21:13:07 +0900 Message-Id: <1301400788-801-3-git-send-email-morita.kazutaka@lab.ntt.co.jp> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <1301400788-801-1-git-send-email-morita.kazutaka@lab.ntt.co.jp> References: <1301400788-801-1-git-send-email-morita.kazutaka@lab.ntt.co.jp> X-Dispatcher: imput version 20070423(IM149) Lines: 58 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Tue, 29 Mar 2011 21:14:53 +0900 (JST) X-Virus-Scanned: clamav-milter 0.97 at sh X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 192.16.179.4 Cc: stefanha@gmail.com, sheepdog@lists.wpkg.org, qemu-devel@nongnu.org, nick@bytemark.co.uk Subject: [Qemu-devel] [PATCH 2/3] sheepdog: allow cancellation of I/Os which are not processed yet X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We can cancel I/O requests safely if they are not sent to the servers. Signed-off-by: MORITA Kazutaka --- block/sheepdog.c | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index cedf806..ed98701 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -421,6 +421,43 @@ static void sd_finish_aiocb(SheepdogAIOCB *acb) static void sd_aio_cancel(BlockDriverAIOCB *blockacb) { SheepdogAIOCB *acb = (SheepdogAIOCB *)blockacb; + BDRVSheepdogState *s = blockacb->bs->opaque; + AIOReq *areq, *next, *oldest_send_req = NULL; + + if (acb->bh) { + /* + * sd_readv_writev_bh_cb() is not called yet, so we can + * release this safely + */ + qemu_bh_delete(acb->bh); + acb->bh = NULL; + qemu_aio_release(acb); + return; + } + + QLIST_FOREACH(areq, &s->outstanding_aio_head, outstanding_aio_siblings) { + if (areq->state == AIO_SEND_OBJREQ) { + oldest_send_req = areq; + } + } + + QLIST_FOREACH_SAFE(areq, &s->outstanding_aio_head, + outstanding_aio_siblings, next) { + if (areq->state == AIO_RECV_OBJREQ) { + continue; + } + if (areq->state == AIO_SEND_OBJREQ && areq == oldest_send_req) { + /* the oldest AIO_SEND_OBJREQ request could be being sent */ + continue; + } + free_aio_req(s, areq); + } + + if (QLIST_EMPTY(&acb->aioreq_head)) { + /* there is no outstanding request */ + qemu_aio_release(acb); + return; + } /* * Sheepdog cannot cancel the requests which are already sent to