From patchwork Tue Oct 9 06:39:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1568971 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by patchwork1.kernel.org (Postfix) with ESMTP id 6A91340135 for ; Tue, 9 Oct 2012 06:44:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q996f0kq006007; Tue, 9 Oct 2012 02:41:02 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q996de0O027129 for ; Tue, 9 Oct 2012 02:39:40 -0400 Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.19]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q996dYwU007595 for ; Tue, 9 Oct 2012 02:39:34 -0400 Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q996dXjC012334 for ; Tue, 9 Oct 2012 02:39:34 -0400 Received: by mail-pa0-f46.google.com with SMTP id hz1so4710419pad.33 for ; Mon, 08 Oct 2012 23:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=D6TdO9whslcqYmcPZGlnzbBFjyWTVpwy0dwaRkBay7g=; b=PK1Hisk6HGHQ2mvts/bjbb3EBjDfOOpdnofNBZl6NsNT4Jnk9Lzkt3J1xjbwJySjQU WO5Cs1Kddgm3P0AhMbekYQBcfNoxHddFDlD7HFWu+DbYm/u5CSRJAyRX1AteL2FX59F2 J5/ezaNnA/WDXaj8PKZ8nw2dyoZh/q9Wjovyc2st3EOyJf/6W5/xmScbegyVo0FsGk0D jR175bCqM32QmLNkvS8cDjMNSUZwTBv40u3jhxcjZyoc1zKpXya52gJZESS74wsCQDu5 2tc6SwV//lYXu4XZWFVGbfGOWKkLZhMB652MMPjGsnzS1v0/qA3tF/MdSaFuJjwEVWR7 8eWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=D6TdO9whslcqYmcPZGlnzbBFjyWTVpwy0dwaRkBay7g=; b=n5X6+KoxmVoQCoCBslUDs+h3Kw1VHnyNdJHtVlLoK2BwW9BK0NpGMyT0JVp5VWZaYN gkhWl7tP8s3S3opKlnbEKr3eJUy0TrCR3mAsI7LTuHAd+W9Mqb+BOv+3g0D6BPxDH006 In74WhIDvm/qZ9xkUx/z6N6bMGvrlD+Ar17MJTNFqNopu4QBYmUuz7ZMaKz0XrcTS8BS UUbUzh+pDdUQnBcb7b6mt60d81n62rFdDRR+G/dB2qUURXBxM5YljDkkJegbuXAfn0u7 XnLocCSzTGZE+kZQPrwUZ7d7sczVrfHs5mHwejiJNty8f6wOzzdJmCnKCcBccplwW2eK kMGA== Received: by 10.68.217.201 with SMTP id pa9mr60497498pbc.45.1349764773751; Mon, 08 Oct 2012 23:39:33 -0700 (PDT) Received: from moria.home.lan (c-67-188-232-164.hsd1.ca.comcast.net. [67.188.232.164]) by mx.google.com with ESMTPS id rr6sm11923736pbc.47.2012.10.08.23.39.32 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 08 Oct 2012 23:39:33 -0700 (PDT) From: Kent Overstreet To: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com, tytso@mit.edu Date: Mon, 8 Oct 2012 23:39:17 -0700 Message-Id: <1349764760-21093-2-git-send-email-koverstreet@google.com> In-Reply-To: <1349764760-21093-1-git-send-email-koverstreet@google.com> References: <1349764760-21093-1-git-send-email-koverstreet@google.com> X-Gm-Message-State: ALoCoQlwSTWcPEMVxUJeXGgrPgOw2n1/AoNAbrliyPkOxl884ZRgzmIzgEiLjttSSCdoxXRL5nwXgeEjOqPuj2k66eDTuSmoCdJUW/a9xNnzjsSzYVS6u2MIsVZndNcAsAyb+4M2aj+9K0mpqUrORViU+zOycFhL/Rw4RTOgtKYCFrKwTFRObGtOGo5AdmyT9noGjpij0t11 X-RedHat-Spam-Score: -4.839 (BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.19 X-loop: dm-devel@redhat.com Cc: Kent Overstreet Subject: [dm-devel] [PATCH 2/5] aio: kiocb_cancel() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Minor refactoring, to get rid of some duplicated code Signed-off-by: Kent Overstreet --- fs/aio.c | 72 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 1ad2d97..95419c4 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -229,6 +229,29 @@ static inline void put_ioctx(struct kioctx *kioctx) __put_ioctx(kioctx); } +static int kiocb_cancel(struct kioctx *ctx, struct kiocb *kiocb, + struct io_event *res) +{ + int (*cancel)(struct kiocb *, struct io_event *); + int ret = -EINVAL; + + cancel = kiocb->ki_cancel; + kiocbSetCancelled(kiocb); + if (cancel) { + kiocb->ki_users++; + spin_unlock_irq(&ctx->ctx_lock); + + memset(res, 0, sizeof(*res)); + res->obj = (u64) kiocb->ki_obj.user; + res->data = kiocb->ki_user_data; + ret = cancel(kiocb, res); + + spin_lock_irq(&ctx->ctx_lock); + } + + return ret; +} + /* ioctx_alloc * Allocates and initializes an ioctx. Returns an ERR_PTR if it failed. */ @@ -304,7 +327,6 @@ out_freectx: */ static void kill_ctx(struct kioctx *ctx) { - int (*cancel)(struct kiocb *, struct io_event *); struct task_struct *tsk = current; DECLARE_WAITQUEUE(wait, tsk); struct io_event res; @@ -315,14 +337,8 @@ static void kill_ctx(struct kioctx *ctx) struct list_head *pos = ctx->active_reqs.next; struct kiocb *iocb = list_kiocb(pos); list_del_init(&iocb->ki_list); - cancel = iocb->ki_cancel; - kiocbSetCancelled(iocb); - if (cancel) { - iocb->ki_users++; - spin_unlock_irq(&ctx->ctx_lock); - cancel(iocb, &res); - spin_lock_irq(&ctx->ctx_lock); - } + + kiocb_cancel(ctx, iocb, &res); } if (!ctx->reqs_active) @@ -1709,7 +1725,7 @@ static struct kiocb *lookup_kiocb(struct kioctx *ctx, struct iocb __user *iocb, SYSCALL_DEFINE3(io_cancel, aio_context_t, ctx_id, struct iocb __user *, iocb, struct io_event __user *, result) { - int (*cancel)(struct kiocb *iocb, struct io_event *res); + struct io_event res; struct kioctx *ctx; struct kiocb *kiocb; u32 key; @@ -1724,32 +1740,22 @@ SYSCALL_DEFINE3(io_cancel, aio_context_t, ctx_id, struct iocb __user *, iocb, return -EINVAL; spin_lock_irq(&ctx->ctx_lock); - ret = -EAGAIN; + kiocb = lookup_kiocb(ctx, iocb, key); - if (kiocb && kiocb->ki_cancel) { - cancel = kiocb->ki_cancel; - kiocb->ki_users ++; - kiocbSetCancelled(kiocb); - } else - cancel = NULL; + if (kiocb) + ret = kiocb_cancel(ctx, kiocb, &res); + else + ret = -EAGAIN; + spin_unlock_irq(&ctx->ctx_lock); - if (NULL != cancel) { - struct io_event tmp; - pr_debug("calling cancel\n"); - memset(&tmp, 0, sizeof(tmp)); - tmp.obj = (u64)(unsigned long)kiocb->ki_obj.user; - tmp.data = kiocb->ki_user_data; - ret = cancel(kiocb, &tmp); - if (!ret) { - /* Cancellation succeeded -- copy the result - * into the user's buffer. - */ - if (copy_to_user(result, &tmp, sizeof(tmp))) - ret = -EFAULT; - } - } else - ret = -EINVAL; + if (!ret) { + /* Cancellation succeeded -- copy the result + * into the user's buffer. + */ + if (copy_to_user(result, &res, sizeof(res))) + ret = -EFAULT; + } put_ioctx(ctx);