diff options
author | Lino Sanfilippo <LinoSanfilippo@gmx.de> | 2013-07-08 18:59:43 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-09 13:33:20 -0400 |
commit | 5e9c070ca085439fbec9e9629dd6171ae325d4d8 (patch) | |
tree | 7d520b51c4b440a6b112e6dbe7a128bcb2a0b0c5 /fs/notify | |
parent | 7b18527c4a95397b443c8c22f75634d5d11c9d47 (diff) |
fanotify: put duplicate code for adding vfsmount/inode marks into an own function
The code under the groups mark_mutex in fanotify_add_inode_mark() and
fanotify_add_vfsmount_mark() is almost identical. So put it into a
seperate function.
Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Cc: Eric Paris <eparis@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/notify')
-rw-r--r-- | fs/notify/fanotify/fanotify_user.c | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 4e1d8ec77b04..e44cb6427df3 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c | |||
@@ -600,33 +600,45 @@ static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark, | |||
600 | return mask & ~oldmask; | 600 | return mask & ~oldmask; |
601 | } | 601 | } |
602 | 602 | ||
603 | static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, | ||
604 | struct inode *inode, | ||
605 | struct vfsmount *mnt) | ||
606 | { | ||
607 | struct fsnotify_mark *mark; | ||
608 | int ret; | ||
609 | |||
610 | if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks) | ||
611 | return ERR_PTR(-ENOSPC); | ||
612 | |||
613 | mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); | ||
614 | if (!mark) | ||
615 | return ERR_PTR(-ENOMEM); | ||
616 | |||
617 | fsnotify_init_mark(mark, fanotify_free_mark); | ||
618 | ret = fsnotify_add_mark_locked(mark, group, inode, mnt, 0); | ||
619 | if (ret) { | ||
620 | fsnotify_put_mark(mark); | ||
621 | return ERR_PTR(ret); | ||
622 | } | ||
623 | |||
624 | return mark; | ||
625 | } | ||
626 | |||
627 | |||
603 | static int fanotify_add_vfsmount_mark(struct fsnotify_group *group, | 628 | static int fanotify_add_vfsmount_mark(struct fsnotify_group *group, |
604 | struct vfsmount *mnt, __u32 mask, | 629 | struct vfsmount *mnt, __u32 mask, |
605 | unsigned int flags) | 630 | unsigned int flags) |
606 | { | 631 | { |
607 | struct fsnotify_mark *fsn_mark; | 632 | struct fsnotify_mark *fsn_mark; |
608 | __u32 added; | 633 | __u32 added; |
609 | int ret = 0; | ||
610 | 634 | ||
611 | mutex_lock(&group->mark_mutex); | 635 | mutex_lock(&group->mark_mutex); |
612 | fsn_mark = fsnotify_find_vfsmount_mark(group, mnt); | 636 | fsn_mark = fsnotify_find_vfsmount_mark(group, mnt); |
613 | if (!fsn_mark) { | 637 | if (!fsn_mark) { |
614 | if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks) { | 638 | fsn_mark = fanotify_add_new_mark(group, NULL, mnt); |
615 | mutex_unlock(&group->mark_mutex); | 639 | if (IS_ERR(fsn_mark)) { |
616 | return -ENOSPC; | ||
617 | } | ||
618 | |||
619 | fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); | ||
620 | if (!fsn_mark) { | ||
621 | mutex_unlock(&group->mark_mutex); | ||
622 | return -ENOMEM; | ||
623 | } | ||
624 | |||
625 | fsnotify_init_mark(fsn_mark, fanotify_free_mark); | ||
626 | ret = fsnotify_add_mark_locked(fsn_mark, group, NULL, mnt, 0); | ||
627 | if (ret) { | ||
628 | mutex_unlock(&group->mark_mutex); | 640 | mutex_unlock(&group->mark_mutex); |
629 | goto err; | 641 | return PTR_ERR(fsn_mark); |
630 | } | 642 | } |
631 | } | 643 | } |
632 | added = fanotify_mark_add_to_mask(fsn_mark, mask, flags); | 644 | added = fanotify_mark_add_to_mask(fsn_mark, mask, flags); |
@@ -634,9 +646,9 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group, | |||
634 | 646 | ||
635 | if (added & ~real_mount(mnt)->mnt_fsnotify_mask) | 647 | if (added & ~real_mount(mnt)->mnt_fsnotify_mask) |
636 | fsnotify_recalc_vfsmount_mask(mnt); | 648 | fsnotify_recalc_vfsmount_mask(mnt); |
637 | err: | 649 | |
638 | fsnotify_put_mark(fsn_mark); | 650 | fsnotify_put_mark(fsn_mark); |
639 | return ret; | 651 | return 0; |
640 | } | 652 | } |
641 | 653 | ||
642 | static int fanotify_add_inode_mark(struct fsnotify_group *group, | 654 | static int fanotify_add_inode_mark(struct fsnotify_group *group, |
@@ -645,7 +657,6 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group, | |||
645 | { | 657 | { |
646 | struct fsnotify_mark *fsn_mark; | 658 | struct fsnotify_mark *fsn_mark; |
647 | __u32 added; | 659 | __u32 added; |
648 | int ret = 0; | ||
649 | 660 | ||
650 | pr_debug("%s: group=%p inode=%p\n", __func__, group, inode); | 661 | pr_debug("%s: group=%p inode=%p\n", __func__, group, inode); |
651 | 662 | ||
@@ -662,22 +673,10 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group, | |||
662 | mutex_lock(&group->mark_mutex); | 673 | mutex_lock(&group->mark_mutex); |
663 | fsn_mark = fsnotify_find_inode_mark(group, inode); | 674 | fsn_mark = fsnotify_find_inode_mark(group, inode); |
664 | if (!fsn_mark) { | 675 | if (!fsn_mark) { |
665 | if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks) { | 676 | fsn_mark = fanotify_add_new_mark(group, inode, NULL); |
677 | if (IS_ERR(fsn_mark)) { | ||
666 | mutex_unlock(&group->mark_mutex); | 678 | mutex_unlock(&group->mark_mutex); |
667 | return -ENOSPC; | 679 | return PTR_ERR(fsn_mark); |
668 | } | ||
669 | |||
670 | fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); | ||
671 | if (!fsn_mark) { | ||
672 | mutex_unlock(&group->mark_mutex); | ||
673 | return -ENOMEM; | ||
674 | } | ||
675 | |||
676 | fsnotify_init_mark(fsn_mark, fanotify_free_mark); | ||
677 | ret = fsnotify_add_mark_locked(fsn_mark, group, inode, NULL, 0); | ||
678 | if (ret) { | ||
679 | mutex_unlock(&group->mark_mutex); | ||
680 | goto err; | ||
681 | } | 680 | } |
682 | } | 681 | } |
683 | added = fanotify_mark_add_to_mask(fsn_mark, mask, flags); | 682 | added = fanotify_mark_add_to_mask(fsn_mark, mask, flags); |
@@ -685,9 +684,9 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group, | |||
685 | 684 | ||
686 | if (added & ~inode->i_fsnotify_mask) | 685 | if (added & ~inode->i_fsnotify_mask) |
687 | fsnotify_recalc_inode_mask(inode); | 686 | fsnotify_recalc_inode_mask(inode); |
688 | err: | 687 | |
689 | fsnotify_put_mark(fsn_mark); | 688 | fsnotify_put_mark(fsn_mark); |
690 | return ret; | 689 | return 0; |
691 | } | 690 | } |
692 | 691 | ||
693 | /* fanotify syscalls */ | 692 | /* fanotify syscalls */ |