fsnotify: take inode->i_lock inside fsnotify_find_mark_entry()
All callers to fsnotify_find_mark_entry() except one take and
release inode->i_lock around the call. Take the lock inside
fsnotify_find_mark_entry() instead.
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
Signed-off-by: Eric Paris <eparis@redhat.com>
diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
index 3efb8b9..cac2eb8 100644
--- a/fs/notify/dnotify/dnotify.c
+++ b/fs/notify/dnotify/dnotify.c
@@ -95,11 +95,7 @@
to_tell = event->to_tell;
- spin_lock(&to_tell->i_lock);
fsn_mark = fsnotify_find_mark(group, to_tell);
- spin_unlock(&to_tell->i_lock);
-
- /* unlikely since we alreay passed dnotify_should_send_event() */
if (unlikely(!fsn_mark))
return 0;
dn_mark = container_of(fsn_mark, struct dnotify_mark, fsn_mark);
@@ -147,11 +143,7 @@
if (!S_ISDIR(inode->i_mode))
return false;
- spin_lock(&inode->i_lock);
fsn_mark = fsnotify_find_mark(group, inode);
- spin_unlock(&inode->i_lock);
-
- /* no mark means no dnotify watch */
if (!fsn_mark)
return false;
@@ -201,9 +193,7 @@
if (!S_ISDIR(inode->i_mode))
return;
- spin_lock(&inode->i_lock);
fsn_mark = fsnotify_find_mark(dnotify_group, inode);
- spin_unlock(&inode->i_lock);
if (!fsn_mark)
return;
dn_mark = container_of(fsn_mark, struct dnotify_mark, fsn_mark);
@@ -356,9 +346,7 @@
mutex_lock(&dnotify_mark_mutex);
/* add the new_fsn_mark or find an old one. */
- spin_lock(&inode->i_lock);
fsn_mark = fsnotify_find_mark(dnotify_group, inode);
- spin_unlock(&inode->i_lock);
if (fsn_mark) {
dn_mark = container_of(fsn_mark, struct dnotify_mark, fsn_mark);
spin_lock(&fsn_mark->lock);
diff --git a/fs/notify/inode_mark.c b/fs/notify/inode_mark.c
index 27c1b43..ba6f983 100644
--- a/fs/notify/inode_mark.c
+++ b/fs/notify/inode_mark.c
@@ -261,12 +261,8 @@
}
}
-/*
- * given a group and inode, find the mark associated with that combination.
- * if found take a reference to that mark and return it, else return NULL
- */
-struct fsnotify_mark *fsnotify_find_mark(struct fsnotify_group *group,
- struct inode *inode)
+static struct fsnotify_mark *fsnotify_find_mark_locked(struct fsnotify_group *group,
+ struct inode *inode)
{
struct fsnotify_mark *mark;
struct hlist_node *pos;
@@ -282,6 +278,22 @@
return NULL;
}
+/*
+ * given a group and inode, find the mark associated with that combination.
+ * if found take a reference to that mark and return it, else return NULL
+ */
+struct fsnotify_mark *fsnotify_find_mark(struct fsnotify_group *group,
+ struct inode *inode)
+{
+ struct fsnotify_mark *mark;
+
+ spin_lock(&inode->i_lock);
+ mark = fsnotify_find_mark_locked(group, inode);
+ spin_unlock(&inode->i_lock);
+
+ return mark;
+}
+
void fsnotify_duplicate_mark(struct fsnotify_mark *new, struct fsnotify_mark *old)
{
assert_spin_locked(&old->lock);
@@ -349,7 +361,7 @@
spin_lock(&inode->i_lock);
if (!allow_dups)
- lmark = fsnotify_find_mark(group, inode);
+ lmark = fsnotify_find_mark_locked(group, inode);
if (!lmark) {
mark->group = group;
mark->i.inode = inode;
diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
index 12dc72b..cc8f6bc 100644
--- a/fs/notify/inotify/inotify_fsnotify.c
+++ b/fs/notify/inotify/inotify_fsnotify.c
@@ -97,9 +97,7 @@
to_tell = event->to_tell;
- spin_lock(&to_tell->i_lock);
fsn_mark = fsnotify_find_mark(group, to_tell);
- spin_unlock(&to_tell->i_lock);
/* race with watch removal? We already passes should_send */
if (unlikely(!fsn_mark))
return 0;
@@ -147,9 +145,7 @@
struct fsnotify_mark *fsn_mark;
bool send;
- spin_lock(&inode->i_lock);
fsn_mark = fsnotify_find_mark(group, inode);
- spin_unlock(&inode->i_lock);
if (!fsn_mark)
return false;
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index 80d102a..ad5a1ea 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -566,9 +566,7 @@
if (unlikely(!mask))
return -EINVAL;
- spin_lock(&inode->i_lock);
fsn_mark = fsnotify_find_mark(group, inode);
- spin_unlock(&inode->i_lock);
if (!fsn_mark)
return -ENOENT;