Commit 3427ce71 authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Jan Kara

fsnotify: clean up fsnotify()

Use helpers to get first and next marks from connector.

Also get rid of inode_node/vfsmount_node local variables, which just refers
to the same objects as iter_info.  There was an srcu_dereference() for
foo_node, but that's completely superfluous since we've already done it
when obtaining foo_node.

Also get rid of inode_group/vfsmount_group local variables; checking
against non-NULL for these is the same as checking against non-NULL
inode_mark/vfsmount_mark.
Reviewed-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent f37650f1
...@@ -243,6 +243,29 @@ static int send_to_group(struct inode *to_tell, ...@@ -243,6 +243,29 @@ static int send_to_group(struct inode *to_tell,
file_name, cookie, iter_info); file_name, cookie, iter_info);
} }
static struct fsnotify_mark *fsnotify_first_mark(struct fsnotify_mark_connector **connp)
{
struct fsnotify_mark_connector *conn;
struct hlist_node *node = NULL;
conn = srcu_dereference(*connp, &fsnotify_mark_srcu);
if (conn)
node = srcu_dereference(conn->list.first, &fsnotify_mark_srcu);
return hlist_entry_safe(node, struct fsnotify_mark, obj_list);
}
static struct fsnotify_mark *fsnotify_next_mark(struct fsnotify_mark *mark)
{
struct hlist_node *node = NULL;
if (mark)
node = srcu_dereference(mark->obj_list.next,
&fsnotify_mark_srcu);
return hlist_entry_safe(node, struct fsnotify_mark, obj_list);
}
/* /*
* This is the main call to fsnotify. The VFS calls into hook specific functions * This is the main call to fsnotify. The VFS calls into hook specific functions
* in linux/fsnotify.h. Those functions then in turn call here. Here will call * in linux/fsnotify.h. Those functions then in turn call here. Here will call
...@@ -252,11 +275,7 @@ static int send_to_group(struct inode *to_tell, ...@@ -252,11 +275,7 @@ static int send_to_group(struct inode *to_tell,
int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
const unsigned char *file_name, u32 cookie) const unsigned char *file_name, u32 cookie)
{ {
struct hlist_node *inode_node = NULL, *vfsmount_node = NULL; struct fsnotify_iter_info iter_info = {};
struct fsnotify_mark *inode_mark = NULL, *vfsmount_mark = NULL;
struct fsnotify_group *inode_group, *vfsmount_group;
struct fsnotify_mark_connector *inode_conn, *vfsmount_conn;
struct fsnotify_iter_info iter_info;
struct mount *mnt; struct mount *mnt;
int ret = 0; int ret = 0;
/* global tests shouldn't care about events on child only the specific event */ /* global tests shouldn't care about events on child only the specific event */
...@@ -291,26 +310,16 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, ...@@ -291,26 +310,16 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
if ((mask & FS_MODIFY) || if ((mask & FS_MODIFY) ||
(test_mask & to_tell->i_fsnotify_mask)) { (test_mask & to_tell->i_fsnotify_mask)) {
inode_conn = srcu_dereference(to_tell->i_fsnotify_marks, iter_info.inode_mark =
&fsnotify_mark_srcu); fsnotify_first_mark(&to_tell->i_fsnotify_marks);
if (inode_conn)
inode_node = srcu_dereference(inode_conn->list.first,
&fsnotify_mark_srcu);
} }
if (mnt && ((mask & FS_MODIFY) || if (mnt && ((mask & FS_MODIFY) ||
(test_mask & mnt->mnt_fsnotify_mask))) { (test_mask & mnt->mnt_fsnotify_mask))) {
inode_conn = srcu_dereference(to_tell->i_fsnotify_marks, iter_info.inode_mark =
&fsnotify_mark_srcu); fsnotify_first_mark(&to_tell->i_fsnotify_marks);
if (inode_conn) iter_info.vfsmount_mark =
inode_node = srcu_dereference(inode_conn->list.first, fsnotify_first_mark(&mnt->mnt_fsnotify_marks);
&fsnotify_mark_srcu);
vfsmount_conn = srcu_dereference(mnt->mnt_fsnotify_marks,
&fsnotify_mark_srcu);
if (vfsmount_conn)
vfsmount_node = srcu_dereference(
vfsmount_conn->list.first,
&fsnotify_mark_srcu);
} }
/* /*
...@@ -318,42 +327,18 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, ...@@ -318,42 +327,18 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
* ignore masks are properly reflected for mount mark notifications. * ignore masks are properly reflected for mount mark notifications.
* That's why this traversal is so complicated... * That's why this traversal is so complicated...
*/ */
while (inode_node || vfsmount_node) { while (iter_info.inode_mark || iter_info.vfsmount_mark) {
inode_group = NULL; struct fsnotify_mark *inode_mark = iter_info.inode_mark;
inode_mark = NULL; struct fsnotify_mark *vfsmount_mark = iter_info.vfsmount_mark;
vfsmount_group = NULL;
vfsmount_mark = NULL; if (inode_mark && vfsmount_mark) {
int cmp = fsnotify_compare_groups(inode_mark->group,
if (inode_node) { vfsmount_mark->group);
inode_mark = hlist_entry(srcu_dereference(inode_node, &fsnotify_mark_srcu), if (cmp > 0)
struct fsnotify_mark, obj_list);
inode_group = inode_mark->group;
}
if (vfsmount_node) {
vfsmount_mark = hlist_entry(srcu_dereference(vfsmount_node, &fsnotify_mark_srcu),
struct fsnotify_mark, obj_list);
vfsmount_group = vfsmount_mark->group;
}
/*
* Need to protect both marks against freeing so that we can
* continue iteration from this place, regardless of which mark
* we actually happen to send an event for.
*/
iter_info.inode_mark = inode_mark;
iter_info.vfsmount_mark = vfsmount_mark;
if (inode_group && vfsmount_group) {
int cmp = fsnotify_compare_groups(inode_group,
vfsmount_group);
if (cmp > 0) {
inode_group = NULL;
inode_mark = NULL; inode_mark = NULL;
} else if (cmp < 0) { else if (cmp < 0)
vfsmount_group = NULL;
vfsmount_mark = NULL; vfsmount_mark = NULL;
} }
}
ret = send_to_group(to_tell, inode_mark, vfsmount_mark, mask, ret = send_to_group(to_tell, inode_mark, vfsmount_mark, mask,
data, data_is, cookie, file_name, data, data_is, cookie, file_name,
...@@ -362,12 +347,12 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, ...@@ -362,12 +347,12 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS)) if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS))
goto out; goto out;
if (inode_group) if (inode_mark)
inode_node = srcu_dereference(inode_node->next, iter_info.inode_mark =
&fsnotify_mark_srcu); fsnotify_next_mark(iter_info.inode_mark);
if (vfsmount_group) if (vfsmount_mark)
vfsmount_node = srcu_dereference(vfsmount_node->next, iter_info.vfsmount_mark =
&fsnotify_mark_srcu); fsnotify_next_mark(iter_info.vfsmount_mark);
} }
ret = 0; ret = 0;
out: out:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment