aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fcntl.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/fcntl.c')
-rw-r--r--fs/fcntl.c66
1 files changed, 50 insertions, 16 deletions
diff --git a/fs/fcntl.c b/fs/fcntl.c
index f8cc34f542c3..dcdbc6f5c33b 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -640,7 +640,7 @@ static void fasync_free_rcu(struct rcu_head *head)
640 * match the state "is the filp on a fasync list". 640 * match the state "is the filp on a fasync list".
641 * 641 *
642 */ 642 */
643static int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp) 643int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp)
644{ 644{
645 struct fasync_struct *fa, **fp; 645 struct fasync_struct *fa, **fp;
646 int result = 0; 646 int result = 0;
@@ -666,21 +666,28 @@ static int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp)
666 return result; 666 return result;
667} 667}
668 668
669struct fasync_struct *fasync_alloc(void)
670{
671 return kmem_cache_alloc(fasync_cache, GFP_KERNEL);
672}
673
669/* 674/*
670 * Add a fasync entry. Return negative on error, positive if 675 * NOTE! This can be used only for unused fasync entries:
671 * added, and zero if did nothing but change an existing one. 676 * entries that actually got inserted on the fasync list
672 * 677 * need to be released by rcu - see fasync_remove_entry.
673 * NOTE! It is very important that the FASYNC flag always
674 * match the state "is the filp on a fasync list".
675 */ 678 */
676static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fapp) 679void fasync_free(struct fasync_struct *new)
677{ 680{
678 struct fasync_struct *new, *fa, **fp; 681 kmem_cache_free(fasync_cache, new);
679 int result = 0; 682}
680 683
681 new = kmem_cache_alloc(fasync_cache, GFP_KERNEL); 684/*
682 if (!new) 685 * Insert a new entry into the fasync list. Return the pointer to the
683 return -ENOMEM; 686 * old one if we didn't use the new one.
687 */
688struct fasync_struct *fasync_insert_entry(int fd, struct file *filp, struct fasync_struct **fapp, struct fasync_struct *new)
689{
690 struct fasync_struct *fa, **fp;
684 691
685 spin_lock(&filp->f_lock); 692 spin_lock(&filp->f_lock);
686 spin_lock(&fasync_lock); 693 spin_lock(&fasync_lock);
@@ -691,8 +698,6 @@ static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fa
691 spin_lock_irq(&fa->fa_lock); 698 spin_lock_irq(&fa->fa_lock);
692 fa->fa_fd = fd; 699 fa->fa_fd = fd;
693 spin_unlock_irq(&fa->fa_lock); 700 spin_unlock_irq(&fa->fa_lock);
694
695 kmem_cache_free(fasync_cache, new);
696 goto out; 701 goto out;
697 } 702 }
698 703
@@ -702,13 +707,42 @@ static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fa
702 new->fa_fd = fd; 707 new->fa_fd = fd;
703 new->fa_next = *fapp; 708 new->fa_next = *fapp;
704 rcu_assign_pointer(*fapp, new); 709 rcu_assign_pointer(*fapp, new);
705 result = 1;
706 filp->f_flags |= FASYNC; 710 filp->f_flags |= FASYNC;
707 711
708out: 712out:
709 spin_unlock(&fasync_lock); 713 spin_unlock(&fasync_lock);
710 spin_unlock(&filp->f_lock); 714 spin_unlock(&filp->f_lock);
711 return result; 715 return fa;
716}
717
718/*
719 * Add a fasync entry. Return negative on error, positive if
720 * added, and zero if did nothing but change an existing one.
721 *
722 * NOTE! It is very important that the FASYNC flag always
723 * match the state "is the filp on a fasync list".
724 */
725static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fapp)
726{
727 struct fasync_struct *new;
728
729 new = fasync_alloc();
730 if (!new)
731 return -ENOMEM;
732
733 /*
734 * fasync_insert_entry() returns the old (update) entry if
735 * it existed.
736 *
737 * So free the (unused) new entry and return 0 to let the
738 * caller know that we didn't add any new fasync entries.
739 */
740 if (fasync_insert_entry(fd, filp, fapp, new)) {
741 fasync_free(new);
742 return 0;
743 }
744
745 return 1;
712} 746}
713 747
714/* 748/*