From: Kent Overstreet <koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
To: linux-bcache-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
tytso-3s7WtUTddSA@public.gmane.org
Cc: Kent Overstreet <koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH 2/5] aio: kiocb_cancel()
Date: Mon, 8 Oct 2012 23:39:17 -0700 [thread overview]
Message-ID: <1349764760-21093-2-git-send-email-koverstreet@google.com> (raw)
In-Reply-To: <1349764760-21093-1-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Minor refactoring, to get rid of some duplicated code
Signed-off-by: Kent Overstreet <koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
---
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);
--
1.7.10.4
next prev parent reply other threads:[~2012-10-09 6:39 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-09 6:39 [PATCH 1/5] aio: Kill return value of aio_complete() Kent Overstreet
[not found] ` <1349764760-21093-1-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-09 6:39 ` Kent Overstreet [this message]
[not found] ` <1349764760-21093-2-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-09 18:26 ` [PATCH 2/5] aio: kiocb_cancel() Zach Brown
[not found] ` <20121009182625.GM26187-fypN+1c5dIyjpB87vu3CluTW4wlIGRCZ@public.gmane.org>
2012-10-09 21:37 ` Kent Overstreet
[not found] ` <20121009213700.GF29494-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-10 11:03 ` Theodore Ts'o
[not found] ` <20121010110356.GA11468-AKGzg7BKzIDYtjvyW6yDsg@public.gmane.org>
2012-10-10 21:20 ` Zach Brown
[not found] ` <20121010212051.GD6371-fypN+1c5dIyjpB87vu3CluTW4wlIGRCZ@public.gmane.org>
2012-10-10 23:21 ` Theodore Ts'o
2012-10-11 2:41 ` Kent Overstreet
2012-10-09 6:39 ` [PATCH 5/5] aio: Refactor aio_read_evt, use cmxchg(), fix bug Kent Overstreet
[not found] ` <1349764760-21093-5-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-09 18:37 ` Zach Brown
[not found] ` <20121009183753.GP26187-fypN+1c5dIyjpB87vu3CluTW4wlIGRCZ@public.gmane.org>
2012-10-09 21:27 ` Kent Overstreet
[not found] ` <20121009212724.GD29494-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-09 22:47 ` Zach Brown
[not found] ` <20121009224703.GT26187-fypN+1c5dIyjpB87vu3CluTW4wlIGRCZ@public.gmane.org>
2012-10-09 22:55 ` Kent Overstreet
[not found] ` <20121009225509.GA26835-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-09 23:10 ` Zach Brown
[not found] ` <20121009231059.GV26187-fypN+1c5dIyjpB87vu3CluTW4wlIGRCZ@public.gmane.org>
2012-10-10 0:06 ` Kent Overstreet
[not found] ` <20121010000600.GB26835-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-10 0:26 ` Zach Brown
[not found] ` <20121010002634.GX26187-fypN+1c5dIyjpB87vu3CluTW4wlIGRCZ@public.gmane.org>
2012-10-10 0:47 ` Kent Overstreet
[not found] ` <20121010004746.GF26835-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-10 21:43 ` Zach Brown
[not found] ` <20121010214315.GE6371-fypN+1c5dIyjpB87vu3CluTW4wlIGRCZ@public.gmane.org>
2012-10-11 2:51 ` Kent Overstreet
[not found] ` <20121011025102.GE24174-jC9Py7bek1znysI04z7BkA@public.gmane.org>
2012-10-11 16:43 ` Zach Brown
2012-10-09 18:25 ` [PATCH 1/5] aio: Kill return value of aio_complete() Zach Brown
2012-10-09 6:39 ` [PATCH 3/5] aio: Rewrite refcounting Kent Overstreet
[not found] ` <1349764760-21093-3-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-09 18:27 ` Zach Brown
[not found] ` <20121009182755.GN26187-fypN+1c5dIyjpB87vu3CluTW4wlIGRCZ@public.gmane.org>
2012-10-09 22:21 ` Kent Overstreet
[not found] ` <20121009222153.GG29494-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-09 22:35 ` Zach Brown
[not found] ` <20121009223504.GS26187-fypN+1c5dIyjpB87vu3CluTW4wlIGRCZ@public.gmane.org>
2012-10-10 0:17 ` Kent Overstreet
2012-10-09 6:39 ` [PATCH 4/5] aio: vmap ringbuffer Kent Overstreet
[not found] ` <1349764760-21093-4-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-09 18:29 ` Zach Brown
2012-10-09 21:31 ` Kent Overstreet
[not found] ` <20121009213111.GE29494-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-09 22:32 ` Zach Brown
2012-10-09 22:44 ` Kent Overstreet
[not found] ` <20121009224428.GH29494-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-09 22:58 ` Zach Brown
[not found] ` <20121009225836.GU26187-fypN+1c5dIyjpB87vu3CluTW4wlIGRCZ@public.gmane.org>
2012-10-10 0:16 ` Kent Overstreet
[not found] ` <20121010001630.GC26835-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-10 0:36 ` Zach Brown
[not found] ` <20121010003626.GY26187-fypN+1c5dIyjpB87vu3CluTW4wlIGRCZ@public.gmane.org>
2012-10-10 1:09 ` Kent Overstreet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1349764760-21093-2-git-send-email-koverstreet@google.com \
--to=koverstreet-hpiqsd4aklfqt0dzr+alfa@public.gmane.org \
--cc=dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=linux-bcache-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=tytso-3s7WtUTddSA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).