fsnotify: Move locking into fsnotify_find_mark()
authorJan Kara <jack@suse.cz>
Wed, 15 Mar 2017 08:33:58 +0000 (09:33 +0100)
committerJan Kara <jack@suse.cz>
Mon, 10 Apr 2017 15:37:35 +0000 (17:37 +0200)
Move locking of a mark list into fsnotify_find_mark(). This reduces code
churn in the following patch changing lock protecting the list.

Reviewed-by: Miklos Szeredi <mszeredi@redhat.com>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/notify/inode_mark.c
fs/notify/mark.c
fs/notify/vfsmount_mark.c

index 9b2f4e6eb8ebdb38aa3f1f0022684ab0621fd8b0..f05fc49b8242c108762d700b7a54bbcce08d3536 100644 (file)
@@ -71,13 +71,7 @@ void fsnotify_clear_inode_marks_by_group(struct fsnotify_group *group)
 struct fsnotify_mark *fsnotify_find_inode_mark(struct fsnotify_group *group,
                                               struct inode *inode)
 {
 struct fsnotify_mark *fsnotify_find_inode_mark(struct fsnotify_group *group,
                                               struct inode *inode)
 {
-       struct fsnotify_mark *mark;
-
-       spin_lock(&inode->i_lock);
-       mark = fsnotify_find_mark(inode->i_fsnotify_marks, group);
-       spin_unlock(&inode->i_lock);
-
-       return mark;
+       return fsnotify_find_mark(inode->i_fsnotify_marks, group);
 }
 
 /**
 }
 
 /**
index 06faf166c7aecbccb8589c52b72f1d08d963409a..0830e0af997a5df9ce67469a7112b8fc483ae3d4 100644 (file)
@@ -485,16 +485,24 @@ struct fsnotify_mark *fsnotify_find_mark(struct fsnotify_mark_connector *conn,
                                         struct fsnotify_group *group)
 {
        struct fsnotify_mark *mark;
                                         struct fsnotify_group *group)
 {
        struct fsnotify_mark *mark;
+       spinlock_t *lock;
 
        if (!conn)
                return NULL;
 
 
        if (!conn)
                return NULL;
 
+       if (conn->flags & FSNOTIFY_OBJ_TYPE_INODE)
+               lock = &conn->inode->i_lock;
+       else
+               lock = &conn->mnt->mnt_root->d_lock;
+       spin_lock(lock);
        hlist_for_each_entry(mark, &conn->list, obj_list) {
                if (mark->group == group) {
                        fsnotify_get_mark(mark);
        hlist_for_each_entry(mark, &conn->list, obj_list) {
                if (mark->group == group) {
                        fsnotify_get_mark(mark);
+                       spin_unlock(lock);
                        return mark;
                }
        }
                        return mark;
                }
        }
+       spin_unlock(lock);
        return NULL;
 }
 
        return NULL;
 }
 
index ffe0d7098cbaca7b8747db5ffc0e0249e8ffd44b..3476ee44b2c5a3783bc7c01a9af484777bf51d1b 100644 (file)
@@ -65,11 +65,6 @@ struct fsnotify_mark *fsnotify_find_vfsmount_mark(struct fsnotify_group *group,
                                                  struct vfsmount *mnt)
 {
        struct mount *m = real_mount(mnt);
                                                  struct vfsmount *mnt)
 {
        struct mount *m = real_mount(mnt);
-       struct fsnotify_mark *mark;
 
 
-       spin_lock(&mnt->mnt_root->d_lock);
-       mark = fsnotify_find_mark(m->mnt_fsnotify_marks, group);
-       spin_unlock(&mnt->mnt_root->d_lock);
-
-       return mark;
+       return fsnotify_find_mark(m->mnt_fsnotify_marks, group);
 }
 }