fsnotify: Move locking into fsnotify_find_mark()
[sfrench/cifs-2.6.git] / fs / notify / vfsmount_mark.c
1 /*
2  *  Copyright (C) 2008 Red Hat, Inc., Eric Paris <eparis@redhat.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2, or (at your option)
7  *  any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; see the file COPYING.  If not, write to
16  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <linux/fs.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/mount.h>
24 #include <linux/mutex.h>
25 #include <linux/spinlock.h>
26
27 #include <linux/atomic.h>
28
29 #include <linux/fsnotify_backend.h>
30 #include "fsnotify.h"
31
32 void fsnotify_clear_vfsmount_marks_by_group(struct fsnotify_group *group)
33 {
34         fsnotify_clear_marks_by_group_flags(group, FSNOTIFY_OBJ_TYPE_VFSMOUNT);
35 }
36
37 void fsnotify_recalc_vfsmount_mask(struct vfsmount *mnt)
38 {
39         fsnotify_recalc_mask(real_mount(mnt)->mnt_fsnotify_marks);
40 }
41
42 void fsnotify_destroy_vfsmount_mark(struct fsnotify_mark *mark)
43 {
44         struct vfsmount *mnt = mark->connector->mnt;
45         struct mount *m = real_mount(mnt);
46
47         BUG_ON(!mutex_is_locked(&mark->group->mark_mutex));
48         assert_spin_locked(&mark->lock);
49
50         spin_lock(&mnt->mnt_root->d_lock);
51
52         hlist_del_init_rcu(&mark->obj_list);
53         mark->connector = NULL;
54
55         spin_unlock(&mnt->mnt_root->d_lock);
56
57         fsnotify_recalc_mask(m->mnt_fsnotify_marks);
58 }
59
60 /*
61  * given a group and vfsmount, find the mark associated with that combination.
62  * if found take a reference to that mark and return it, else return NULL
63  */
64 struct fsnotify_mark *fsnotify_find_vfsmount_mark(struct fsnotify_group *group,
65                                                   struct vfsmount *mnt)
66 {
67         struct mount *m = real_mount(mnt);
68
69         return fsnotify_find_mark(m->mnt_fsnotify_marks, group);
70 }