Commit ce8f76fb authored by Eric Paris's avatar Eric Paris

fsnotify: pass both the vfsmount mark and inode mark

should_send_event() and handle_event() will both need to look up the inode
event if they get a vfsmount event.  Lets just pass both at the same time
since we have them both after walking the lists in lockstep.
Signed-off-by: default avatarEric Paris <eparis@redhat.com>
parent 613a807f
...@@ -83,7 +83,8 @@ static void dnotify_recalc_inode_mask(struct fsnotify_mark *fsn_mark) ...@@ -83,7 +83,8 @@ static void dnotify_recalc_inode_mask(struct fsnotify_mark *fsn_mark)
* events. * events.
*/ */
static int dnotify_handle_event(struct fsnotify_group *group, static int dnotify_handle_event(struct fsnotify_group *group,
struct fsnotify_mark *mark, struct fsnotify_mark *inode_mark,
struct fsnotify_mark *vfsmount_mark,
struct fsnotify_event *event) struct fsnotify_event *event)
{ {
struct dnotify_mark *dn_mark; struct dnotify_mark *dn_mark;
...@@ -93,11 +94,13 @@ static int dnotify_handle_event(struct fsnotify_group *group, ...@@ -93,11 +94,13 @@ static int dnotify_handle_event(struct fsnotify_group *group,
struct fown_struct *fown; struct fown_struct *fown;
__u32 test_mask = event->mask & ~FS_EVENT_ON_CHILD; __u32 test_mask = event->mask & ~FS_EVENT_ON_CHILD;
BUG_ON(vfsmount_mark);
to_tell = event->to_tell; to_tell = event->to_tell;
dn_mark = container_of(mark, struct dnotify_mark, fsn_mark); dn_mark = container_of(inode_mark, struct dnotify_mark, fsn_mark);
spin_lock(&mark->lock); spin_lock(&inode_mark->lock);
prev = &dn_mark->dn; prev = &dn_mark->dn;
while ((dn = *prev) != NULL) { while ((dn = *prev) != NULL) {
if ((dn->dn_mask & test_mask) == 0) { if ((dn->dn_mask & test_mask) == 0) {
...@@ -111,11 +114,11 @@ static int dnotify_handle_event(struct fsnotify_group *group, ...@@ -111,11 +114,11 @@ static int dnotify_handle_event(struct fsnotify_group *group,
else { else {
*prev = dn->dn_next; *prev = dn->dn_next;
kmem_cache_free(dnotify_struct_cache, dn); kmem_cache_free(dnotify_struct_cache, dn);
dnotify_recalc_inode_mask(mark); dnotify_recalc_inode_mask(inode_mark);
} }
} }
spin_unlock(&mark->lock); spin_unlock(&inode_mark->lock);
return 0; return 0;
} }
...@@ -126,8 +129,9 @@ static int dnotify_handle_event(struct fsnotify_group *group, ...@@ -126,8 +129,9 @@ static int dnotify_handle_event(struct fsnotify_group *group,
*/ */
static bool dnotify_should_send_event(struct fsnotify_group *group, static bool dnotify_should_send_event(struct fsnotify_group *group,
struct inode *inode, struct vfsmount *mnt, struct inode *inode, struct vfsmount *mnt,
struct fsnotify_mark *mark, __u32 mask, struct fsnotify_mark *inode_mark,
void *data, int data_type) struct fsnotify_mark *vfsmount_mark,
__u32 mask, void *data, int data_type)
{ {
/* not a dir, dnotify doesn't care */ /* not a dir, dnotify doesn't care */
if (!S_ISDIR(inode->i_mode)) if (!S_ISDIR(inode->i_mode))
......
...@@ -115,7 +115,8 @@ static int fanotify_get_response_from_access(struct fsnotify_group *group, ...@@ -115,7 +115,8 @@ static int fanotify_get_response_from_access(struct fsnotify_group *group,
#endif #endif
static int fanotify_handle_event(struct fsnotify_group *group, static int fanotify_handle_event(struct fsnotify_group *group,
struct fsnotify_mark *mark, struct fsnotify_mark *inode_mark,
struct fsnotify_mark *fanotify_mark,
struct fsnotify_event *event) struct fsnotify_event *event)
{ {
int ret = 0; int ret = 0;
...@@ -196,8 +197,11 @@ static bool should_send_inode_event(struct fsnotify_group *group, ...@@ -196,8 +197,11 @@ static bool should_send_inode_event(struct fsnotify_group *group,
return true; return true;
} }
static bool fanotify_should_send_event(struct fsnotify_group *group, struct inode *to_tell, static bool fanotify_should_send_event(struct fsnotify_group *group,
struct vfsmount *mnt, struct fsnotify_mark *mark, struct inode *to_tell,
struct vfsmount *mnt,
struct fsnotify_mark *inode_mark,
struct fsnotify_mark *vfsmount_mark,
__u32 mask, void *data, int data_type) __u32 mask, void *data, int data_type)
{ {
pr_debug("%s: group=%p to_tell=%p mnt=%p mask=%x data=%p data_type=%d\n", pr_debug("%s: group=%p to_tell=%p mnt=%p mask=%x data=%p data_type=%d\n",
...@@ -213,9 +217,10 @@ static bool fanotify_should_send_event(struct fsnotify_group *group, struct inod ...@@ -213,9 +217,10 @@ static bool fanotify_should_send_event(struct fsnotify_group *group, struct inod
return false; return false;
if (mnt) if (mnt)
return should_send_vfsmount_event(group, mnt, to_tell, mark, mask); return should_send_vfsmount_event(group, mnt, to_tell,
vfsmount_mark, mask);
else else
return should_send_inode_event(group, to_tell, mark, mask); return should_send_inode_event(group, to_tell, inode_mark, mask);
} }
const struct fsnotify_ops fanotify_fsnotify_ops = { const struct fsnotify_ops fanotify_fsnotify_ops = {
......
...@@ -141,28 +141,51 @@ void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask) ...@@ -141,28 +141,51 @@ void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
EXPORT_SYMBOL_GPL(__fsnotify_parent); EXPORT_SYMBOL_GPL(__fsnotify_parent);
static int send_to_group(struct inode *to_tell, struct vfsmount *mnt, static int send_to_group(struct inode *to_tell, struct vfsmount *mnt,
struct fsnotify_mark *mark, struct fsnotify_mark *inode_mark,
__u32 mask, void *data, struct fsnotify_mark *vfsmount_mark,
__u32 mask, void *data,
int data_is, u32 cookie, int data_is, u32 cookie,
const unsigned char *file_name, const unsigned char *file_name,
struct fsnotify_event **event) struct fsnotify_event **event)
{ {
struct fsnotify_group *group = mark->group; struct fsnotify_group *group = inode_mark->group;
__u32 test_mask = (mask & ~FS_EVENT_ON_CHILD); __u32 inode_test_mask = (mask & ~FS_EVENT_ON_CHILD);
__u32 vfsmount_test_mask = (mask & ~FS_EVENT_ON_CHILD);
pr_debug("%s: group=%p to_tell=%p mnt=%p mark=%p mask=%x data=%p" pr_debug("%s: group=%p to_tell=%p mnt=%p mark=%p mask=%x data=%p"
" data_is=%d cookie=%d event=%p\n", __func__, group, to_tell, " data_is=%d cookie=%d event=%p\n", __func__, group, to_tell,
mnt, mark, mask, data, data_is, cookie, *event); mnt, inode_mark, mask, data, data_is, cookie, *event);
/* clear ignored on inode modification */
if (mask & FS_MODIFY) {
if (inode_mark &&
!(inode_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY))
inode_mark->ignored_mask = 0;
if (vfsmount_mark &&
!(vfsmount_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY))
vfsmount_mark->ignored_mask = 0;
}
if ((mask & FS_MODIFY) && /* does the inode mark tell us to do something? */
!(mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY)) if (inode_mark) {
mark->ignored_mask = 0; inode_test_mask &= inode_mark->mask;
inode_test_mask &= ~inode_mark->ignored_mask;
}
if (!(test_mask & mark->mask & ~mark->ignored_mask)) /* does the vfsmount_mark tell us to do something? */
if (vfsmount_mark) {
vfsmount_test_mask &= vfsmount_mark->mask;
vfsmount_test_mask &= ~vfsmount_mark->ignored_mask;
if (inode_mark)
vfsmount_test_mask &= ~inode_mark->ignored_mask;
}
if (!inode_test_mask && !vfsmount_test_mask)
return 0; return 0;
if (group->ops->should_send_event(group, to_tell, mnt, mark, mask, if (group->ops->should_send_event(group, to_tell, mnt, inode_mark,
data, data_is) == false) vfsmount_mark, mask, data,
data_is) == false)
return 0; return 0;
if (!*event) { if (!*event) {
...@@ -172,7 +195,7 @@ static int send_to_group(struct inode *to_tell, struct vfsmount *mnt, ...@@ -172,7 +195,7 @@ static int send_to_group(struct inode *to_tell, struct vfsmount *mnt,
if (!*event) if (!*event)
return -ENOMEM; return -ENOMEM;
} }
return group->ops->handle_event(group, mark, *event); return group->ops->handle_event(group, inode_mark, vfsmount_mark, *event);
} }
/* /*
...@@ -213,14 +236,16 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, ...@@ -213,14 +236,16 @@ int fsnotify(struct inode *to_tell, __u32 mask, 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_node = to_tell->i_fsnotify_marks.first; inode_node = srcu_dereference(to_tell->i_fsnotify_marks.first,
&fsnotify_mark_srcu);
else else
inode_node = NULL; inode_node = NULL;
if (mnt) { if (mnt) {
if ((mask & FS_MODIFY) || if ((mask & FS_MODIFY) ||
(test_mask & mnt->mnt_fsnotify_mask)) (test_mask & mnt->mnt_fsnotify_mask))
vfsmount_node = mnt->mnt_fsnotify_marks.first; vfsmount_node = srcu_dereference(mnt->mnt_fsnotify_marks.first,
&fsnotify_mark_srcu);
else else
vfsmount_node = NULL; vfsmount_node = NULL;
} else { } else {
...@@ -245,26 +270,27 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, ...@@ -245,26 +270,27 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
if (inode_group < vfsmount_group) { if (inode_group < vfsmount_group) {
/* handle inode */ /* handle inode */
send_to_group(to_tell, NULL, inode_mark, mask, data, send_to_group(to_tell, NULL, inode_mark, NULL, mask, data,
data_is, cookie, file_name, &event); data_is, cookie, file_name, &event);
used_inode = true; used_inode = true;
} else if (vfsmount_group < inode_group) { } else if (vfsmount_group < inode_group) {
send_to_group(to_tell, mnt, vfsmount_mark, mask, data, send_to_group(to_tell, mnt, NULL, vfsmount_mark, mask, data,
data_is, cookie, file_name, &event); data_is, cookie, file_name, &event);
used_vfsmount = true; used_vfsmount = true;
} else { } else {
send_to_group(to_tell, mnt, vfsmount_mark, mask, data, send_to_group(to_tell, mnt, inode_mark, vfsmount_mark,
data_is, cookie, file_name, &event); mask, data, data_is, cookie, file_name,
&event);
used_vfsmount = true; used_vfsmount = true;
send_to_group(to_tell, NULL, inode_mark, mask, data,
data_is, cookie, file_name, &event);
used_inode = true; used_inode = true;
} }
if (used_inode) if (used_inode)
inode_node = inode_node->next; inode_node = srcu_dereference(inode_node->next,
&fsnotify_mark_srcu);
if (used_vfsmount) if (used_vfsmount)
vfsmount_node = vfsmount_node->next; vfsmount_node = srcu_dereference(vfsmount_node->next,
&fsnotify_mark_srcu);
} }
srcu_read_unlock(&fsnotify_mark_srcu, idx); srcu_read_unlock(&fsnotify_mark_srcu, idx);
......
...@@ -90,7 +90,8 @@ static struct fsnotify_event *inotify_merge(struct list_head *list, ...@@ -90,7 +90,8 @@ static struct fsnotify_event *inotify_merge(struct list_head *list,
} }
static int inotify_handle_event(struct fsnotify_group *group, static int inotify_handle_event(struct fsnotify_group *group,
struct fsnotify_mark *mark, struct fsnotify_mark *inode_mark,
struct fsnotify_mark *vfsmount_mark,
struct fsnotify_event *event) struct fsnotify_event *event)
{ {
struct inotify_inode_mark *i_mark; struct inotify_inode_mark *i_mark;
...@@ -100,12 +101,14 @@ static int inotify_handle_event(struct fsnotify_group *group, ...@@ -100,12 +101,14 @@ static int inotify_handle_event(struct fsnotify_group *group,
struct fsnotify_event *added_event; struct fsnotify_event *added_event;
int wd, ret = 0; int wd, ret = 0;
BUG_ON(vfsmount_mark);
pr_debug("%s: group=%p event=%p to_tell=%p mask=%x\n", __func__, group, pr_debug("%s: group=%p event=%p to_tell=%p mask=%x\n", __func__, group,
event, event->to_tell, event->mask); event, event->to_tell, event->mask);
to_tell = event->to_tell; to_tell = event->to_tell;
i_mark = container_of(mark, struct inotify_inode_mark, i_mark = container_of(inode_mark, struct inotify_inode_mark,
fsn_mark); fsn_mark);
wd = i_mark->wd; wd = i_mark->wd;
...@@ -127,8 +130,8 @@ static int inotify_handle_event(struct fsnotify_group *group, ...@@ -127,8 +130,8 @@ static int inotify_handle_event(struct fsnotify_group *group,
ret = PTR_ERR(added_event); ret = PTR_ERR(added_event);
} }
if (mark->mask & IN_ONESHOT) if (inode_mark->mask & IN_ONESHOT)
fsnotify_destroy_mark(mark); fsnotify_destroy_mark(inode_mark);
return ret; return ret;
} }
...@@ -140,6 +143,7 @@ static void inotify_freeing_mark(struct fsnotify_mark *fsn_mark, struct fsnotify ...@@ -140,6 +143,7 @@ static void inotify_freeing_mark(struct fsnotify_mark *fsn_mark, struct fsnotify
static bool inotify_should_send_event(struct fsnotify_group *group, struct inode *inode, static bool inotify_should_send_event(struct fsnotify_group *group, struct inode *inode,
struct vfsmount *mnt, struct fsnotify_mark *mark, struct vfsmount *mnt, struct fsnotify_mark *mark,
struct fsnotify_mark *vfsmount_mark,
__u32 mask, void *data, int data_type) __u32 mask, void *data, int data_type)
{ {
if ((mark->mask & FS_EXCL_UNLINK) && if ((mark->mask & FS_EXCL_UNLINK) &&
......
...@@ -92,9 +92,12 @@ struct fsnotify_event_private_data; ...@@ -92,9 +92,12 @@ struct fsnotify_event_private_data;
*/ */
struct fsnotify_ops { struct fsnotify_ops {
bool (*should_send_event)(struct fsnotify_group *group, struct inode *inode, bool (*should_send_event)(struct fsnotify_group *group, struct inode *inode,
struct vfsmount *mnt, struct fsnotify_mark *mark, struct vfsmount *mnt, struct fsnotify_mark *inode_mark,
struct fsnotify_mark *vfsmount_mark,
__u32 mask, void *data, int data_type); __u32 mask, void *data, int data_type);
int (*handle_event)(struct fsnotify_group *group, struct fsnotify_mark *mark, int (*handle_event)(struct fsnotify_group *group,
struct fsnotify_mark *inode_mark,
struct fsnotify_mark *vfsmount_mark,
struct fsnotify_event *event); struct fsnotify_event *event);
void (*free_group_priv)(struct fsnotify_group *group); void (*free_group_priv)(struct fsnotify_group *group);
void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group); void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
......
...@@ -904,7 +904,8 @@ static void evict_chunk(struct audit_chunk *chunk) ...@@ -904,7 +904,8 @@ static void evict_chunk(struct audit_chunk *chunk)
} }
static int audit_tree_handle_event(struct fsnotify_group *group, static int audit_tree_handle_event(struct fsnotify_group *group,
struct fsnotify_mark *mark, struct fsnotify_mark *inode_mark,
struct fsnotify_mark *vfsmonut_mark,
struct fsnotify_event *event) struct fsnotify_event *event)
{ {
BUG(); BUG();
...@@ -920,7 +921,8 @@ static void audit_tree_freeing_mark(struct fsnotify_mark *entry, struct fsnotify ...@@ -920,7 +921,8 @@ static void audit_tree_freeing_mark(struct fsnotify_mark *entry, struct fsnotify
} }
static bool audit_tree_send_event(struct fsnotify_group *group, struct inode *inode, static bool audit_tree_send_event(struct fsnotify_group *group, struct inode *inode,
struct vfsmount *mnt, struct fsnotify_mark *mark, struct vfsmount *mnt, struct fsnotify_mark *inode_mark,
struct fsnotify_mark *vfsmount_mark,
__u32 mask, void *data, int data_type) __u32 mask, void *data, int data_type)
{ {
return false; return false;
......
...@@ -503,7 +503,8 @@ void audit_remove_watch_rule(struct audit_krule *krule) ...@@ -503,7 +503,8 @@ void audit_remove_watch_rule(struct audit_krule *krule)
} }
static bool audit_watch_should_send_event(struct fsnotify_group *group, struct inode *inode, static bool audit_watch_should_send_event(struct fsnotify_group *group, struct inode *inode,
struct vfsmount *mnt, struct fsnotify_mark *mark, struct vfsmount *mnt, struct fsnotify_mark *inode_mark,
struct fsnotify_mark *vfsmount_mark,
__u32 mask, void *data, int data_type) __u32 mask, void *data, int data_type)
{ {
return true; return true;
...@@ -511,7 +512,8 @@ static bool audit_watch_should_send_event(struct fsnotify_group *group, struct i ...@@ -511,7 +512,8 @@ static bool audit_watch_should_send_event(struct fsnotify_group *group, struct i
/* Update watch data in audit rules based on fsnotify events. */ /* Update watch data in audit rules based on fsnotify events. */
static int audit_watch_handle_event(struct fsnotify_group *group, static int audit_watch_handle_event(struct fsnotify_group *group,
struct fsnotify_mark *mark, struct fsnotify_mark *inode_mark,
struct fsnotify_mark *vfsmount_mark,
struct fsnotify_event *event) struct fsnotify_event *event)
{ {
struct inode *inode; struct inode *inode;
...@@ -519,7 +521,7 @@ static int audit_watch_handle_event(struct fsnotify_group *group, ...@@ -519,7 +521,7 @@ static int audit_watch_handle_event(struct fsnotify_group *group,
const char *dname = event->file_name; const char *dname = event->file_name;
struct audit_parent *parent; struct audit_parent *parent;
parent = container_of(mark, struct audit_parent, mark); parent = container_of(inode_mark, struct audit_parent, mark);
BUG_ON(group != audit_watch_group); BUG_ON(group != audit_watch_group);
......
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