aboutsummaryrefslogtreecommitdiffstats
path: root/fs/aio.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/aio.c')
-rw-r--r--fs/aio.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/fs/aio.c b/fs/aio.c
index 20bb919eb195..5a28b69ad223 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -457,6 +457,8 @@ static inline struct kiocb *aio_get_req(struct kioctx *ctx)
457 457
458static inline void really_put_req(struct kioctx *ctx, struct kiocb *req) 458static inline void really_put_req(struct kioctx *ctx, struct kiocb *req)
459{ 459{
460 assert_spin_locked(&ctx->ctx_lock);
461
460 if (req->ki_dtor) 462 if (req->ki_dtor)
461 req->ki_dtor(req); 463 req->ki_dtor(req);
462 kmem_cache_free(kiocb_cachep, req); 464 kmem_cache_free(kiocb_cachep, req);
@@ -498,6 +500,8 @@ static int __aio_put_req(struct kioctx *ctx, struct kiocb *req)
498 dprintk(KERN_DEBUG "aio_put(%p): f_count=%d\n", 500 dprintk(KERN_DEBUG "aio_put(%p): f_count=%d\n",
499 req, atomic_read(&req->ki_filp->f_count)); 501 req, atomic_read(&req->ki_filp->f_count));
500 502
503 assert_spin_locked(&ctx->ctx_lock);
504
501 req->ki_users --; 505 req->ki_users --;
502 if (unlikely(req->ki_users < 0)) 506 if (unlikely(req->ki_users < 0))
503 BUG(); 507 BUG();
@@ -619,14 +623,13 @@ static void unuse_mm(struct mm_struct *mm)
619 * the kiocb (to tell the caller to activate the work 623 * the kiocb (to tell the caller to activate the work
620 * queue to process it), or 0, if it found that it was 624 * queue to process it), or 0, if it found that it was
621 * already queued. 625 * already queued.
622 *
623 * Should be called with the spin lock iocb->ki_ctx->ctx_lock
624 * held
625 */ 626 */
626static inline int __queue_kicked_iocb(struct kiocb *iocb) 627static inline int __queue_kicked_iocb(struct kiocb *iocb)
627{ 628{
628 struct kioctx *ctx = iocb->ki_ctx; 629 struct kioctx *ctx = iocb->ki_ctx;
629 630
631 assert_spin_locked(&ctx->ctx_lock);
632
630 if (list_empty(&iocb->ki_run_list)) { 633 if (list_empty(&iocb->ki_run_list)) {
631 list_add_tail(&iocb->ki_run_list, 634 list_add_tail(&iocb->ki_run_list,
632 &ctx->run_list); 635 &ctx->run_list);
@@ -771,13 +774,15 @@ out:
771 * Process all pending retries queued on the ioctx 774 * Process all pending retries queued on the ioctx
772 * run list. 775 * run list.
773 * Assumes it is operating within the aio issuer's mm 776 * Assumes it is operating within the aio issuer's mm
774 * context. Expects to be called with ctx->ctx_lock held 777 * context.
775 */ 778 */
776static int __aio_run_iocbs(struct kioctx *ctx) 779static int __aio_run_iocbs(struct kioctx *ctx)
777{ 780{
778 struct kiocb *iocb; 781 struct kiocb *iocb;
779 LIST_HEAD(run_list); 782 LIST_HEAD(run_list);
780 783
784 assert_spin_locked(&ctx->ctx_lock);
785
781 list_splice_init(&ctx->run_list, &run_list); 786 list_splice_init(&ctx->run_list, &run_list);
782 while (!list_empty(&run_list)) { 787 while (!list_empty(&run_list)) {
783 iocb = list_entry(run_list.next, struct kiocb, 788 iocb = list_entry(run_list.next, struct kiocb,
@@ -937,28 +942,19 @@ int fastcall aio_complete(struct kiocb *iocb, long res, long res2)
937 unsigned long tail; 942 unsigned long tail;
938 int ret; 943 int ret;
939 944
940 /* Special case handling for sync iocbs: events go directly 945 /*
941 * into the iocb for fast handling. Note that this will not 946 * Special case handling for sync iocbs:
942 * work if we allow sync kiocbs to be cancelled. in which 947 * - events go directly into the iocb for fast handling
943 * case the usage count checks will have to move under ctx_lock 948 * - the sync task with the iocb in its stack holds the single iocb
944 * for all cases. 949 * ref, no other paths have a way to get another ref
950 * - the sync task helpfully left a reference to itself in the iocb
945 */ 951 */
946 if (is_sync_kiocb(iocb)) { 952 if (is_sync_kiocb(iocb)) {
947 int ret; 953 BUG_ON(iocb->ki_users != 1);
948
949 iocb->ki_user_data = res; 954 iocb->ki_user_data = res;
950 if (iocb->ki_users == 1) { 955 iocb->ki_users = 0;
951 iocb->ki_users = 0;
952 ret = 1;
953 } else {
954 spin_lock_irq(&ctx->ctx_lock);
955 iocb->ki_users--;
956 ret = (0 == iocb->ki_users);
957 spin_unlock_irq(&ctx->ctx_lock);
958 }
959 /* sync iocbs put the task here for us */
960 wake_up_process(iocb->ki_obj.tsk); 956 wake_up_process(iocb->ki_obj.tsk);
961 return ret; 957 return 1;
962 } 958 }
963 959
964 info = &ctx->ring_info; 960 info = &ctx->ring_info;
@@ -1613,12 +1609,14 @@ asmlinkage long sys_io_submit(aio_context_t ctx_id, long nr,
1613 1609
1614/* lookup_kiocb 1610/* lookup_kiocb
1615 * Finds a given iocb for cancellation. 1611 * Finds a given iocb for cancellation.
1616 * MUST be called with ctx->ctx_lock held.
1617 */ 1612 */
1618static struct kiocb *lookup_kiocb(struct kioctx *ctx, struct iocb __user *iocb, 1613static struct kiocb *lookup_kiocb(struct kioctx *ctx, struct iocb __user *iocb,
1619 u32 key) 1614 u32 key)
1620{ 1615{
1621 struct list_head *pos; 1616 struct list_head *pos;
1617
1618 assert_spin_locked(&ctx->ctx_lock);
1619
1622 /* TODO: use a hash or array, this sucks. */ 1620 /* TODO: use a hash or array, this sucks. */
1623 list_for_each(pos, &ctx->active_reqs) { 1621 list_for_each(pos, &ctx->active_reqs) {
1624 struct kiocb *kiocb = list_kiocb(pos); 1622 struct kiocb *kiocb = list_kiocb(pos);