aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/aio.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/fs/aio.c b/fs/aio.c
index 588aff9dc316..3bc068c1cb9c 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -475,7 +475,7 @@ static int ioctx_add_table(struct kioctx *ctx, struct mm_struct *mm)
475 struct aio_ring *ring; 475 struct aio_ring *ring;
476 476
477 spin_lock(&mm->ioctx_lock); 477 spin_lock(&mm->ioctx_lock);
478 table = rcu_dereference(mm->ioctx_table); 478 table = mm->ioctx_table;
479 479
480 while (1) { 480 while (1) {
481 if (table) 481 if (table)
@@ -503,7 +503,7 @@ static int ioctx_add_table(struct kioctx *ctx, struct mm_struct *mm)
503 table->nr = new_nr; 503 table->nr = new_nr;
504 504
505 spin_lock(&mm->ioctx_lock); 505 spin_lock(&mm->ioctx_lock);
506 old = rcu_dereference(mm->ioctx_table); 506 old = mm->ioctx_table;
507 507
508 if (!old) { 508 if (!old) {
509 rcu_assign_pointer(mm->ioctx_table, table); 509 rcu_assign_pointer(mm->ioctx_table, table);
@@ -579,10 +579,6 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
579 if (ctx->req_batch < 1) 579 if (ctx->req_batch < 1)
580 ctx->req_batch = 1; 580 ctx->req_batch = 1;
581 581
582 err = ioctx_add_table(ctx, mm);
583 if (err)
584 goto out_cleanup_noerr;
585
586 /* limit the number of system wide aios */ 582 /* limit the number of system wide aios */
587 spin_lock(&aio_nr_lock); 583 spin_lock(&aio_nr_lock);
588 if (aio_nr + nr_events > (aio_max_nr * 2UL) || 584 if (aio_nr + nr_events > (aio_max_nr * 2UL) ||
@@ -595,13 +591,18 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
595 591
596 percpu_ref_get(&ctx->users); /* io_setup() will drop this ref */ 592 percpu_ref_get(&ctx->users); /* io_setup() will drop this ref */
597 593
594 err = ioctx_add_table(ctx, mm);
595 if (err)
596 goto out_cleanup_put;
597
598 pr_debug("allocated ioctx %p[%ld]: mm=%p mask=0x%x\n", 598 pr_debug("allocated ioctx %p[%ld]: mm=%p mask=0x%x\n",
599 ctx, ctx->user_id, mm, ctx->nr_events); 599 ctx, ctx->user_id, mm, ctx->nr_events);
600 return ctx; 600 return ctx;
601 601
602out_cleanup_put:
603 percpu_ref_put(&ctx->users);
602out_cleanup: 604out_cleanup:
603 err = -EAGAIN; 605 err = -EAGAIN;
604out_cleanup_noerr:
605 aio_free_ring(ctx); 606 aio_free_ring(ctx);
606out_freepcpu: 607out_freepcpu:
607 free_percpu(ctx->cpu); 608 free_percpu(ctx->cpu);
@@ -626,7 +627,7 @@ static void kill_ioctx(struct mm_struct *mm, struct kioctx *ctx)
626 struct kioctx_table *table; 627 struct kioctx_table *table;
627 628
628 spin_lock(&mm->ioctx_lock); 629 spin_lock(&mm->ioctx_lock);
629 table = rcu_dereference(mm->ioctx_table); 630 table = mm->ioctx_table;
630 631
631 WARN_ON(ctx != table->table[ctx->id]); 632 WARN_ON(ctx != table->table[ctx->id]);
632 table->table[ctx->id] = NULL; 633 table->table[ctx->id] = NULL;