fsnotify: pass connp and object type to fsnotify_add_mark()
Instead of passing inode and vfsmount arguments to fsnotify_add_mark() and its _locked variant, pass an abstract object pointer and the object type. The helpers fsnotify_obj_{inode,mount} are added to get the concrete object pointer from abstract object pointer. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
This commit is contained in:
parent
9b6e543450
commit
b812a9f589
@ -615,8 +615,8 @@ static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
|
static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
|
||||||
struct inode *inode,
|
fsnotify_connp_t *connp,
|
||||||
struct vfsmount *mnt)
|
unsigned int type)
|
||||||
{
|
{
|
||||||
struct fsnotify_mark *mark;
|
struct fsnotify_mark *mark;
|
||||||
int ret;
|
int ret;
|
||||||
@ -629,7 +629,7 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
|
|||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
fsnotify_init_mark(mark, group);
|
fsnotify_init_mark(mark, group);
|
||||||
ret = fsnotify_add_mark_locked(mark, inode, mnt, 0);
|
ret = fsnotify_add_mark_locked(mark, connp, type, 0);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fsnotify_put_mark(mark);
|
fsnotify_put_mark(mark);
|
||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
@ -643,14 +643,15 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group,
|
|||||||
struct vfsmount *mnt, __u32 mask,
|
struct vfsmount *mnt, __u32 mask,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
|
fsnotify_connp_t *connp = &real_mount(mnt)->mnt_fsnotify_marks;
|
||||||
struct fsnotify_mark *fsn_mark;
|
struct fsnotify_mark *fsn_mark;
|
||||||
__u32 added;
|
__u32 added;
|
||||||
|
|
||||||
mutex_lock(&group->mark_mutex);
|
mutex_lock(&group->mark_mutex);
|
||||||
fsn_mark = fsnotify_find_mark(&real_mount(mnt)->mnt_fsnotify_marks,
|
fsn_mark = fsnotify_find_mark(connp, group);
|
||||||
group);
|
|
||||||
if (!fsn_mark) {
|
if (!fsn_mark) {
|
||||||
fsn_mark = fanotify_add_new_mark(group, NULL, mnt);
|
fsn_mark = fanotify_add_new_mark(group, connp,
|
||||||
|
FSNOTIFY_OBJ_TYPE_VFSMOUNT);
|
||||||
if (IS_ERR(fsn_mark)) {
|
if (IS_ERR(fsn_mark)) {
|
||||||
mutex_unlock(&group->mark_mutex);
|
mutex_unlock(&group->mark_mutex);
|
||||||
return PTR_ERR(fsn_mark);
|
return PTR_ERR(fsn_mark);
|
||||||
@ -669,6 +670,7 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
|
|||||||
struct inode *inode, __u32 mask,
|
struct inode *inode, __u32 mask,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
|
fsnotify_connp_t *connp = &inode->i_fsnotify_marks;
|
||||||
struct fsnotify_mark *fsn_mark;
|
struct fsnotify_mark *fsn_mark;
|
||||||
__u32 added;
|
__u32 added;
|
||||||
|
|
||||||
@ -685,9 +687,10 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
mutex_lock(&group->mark_mutex);
|
mutex_lock(&group->mark_mutex);
|
||||||
fsn_mark = fsnotify_find_mark(&inode->i_fsnotify_marks, group);
|
fsn_mark = fsnotify_find_mark(connp, group);
|
||||||
if (!fsn_mark) {
|
if (!fsn_mark) {
|
||||||
fsn_mark = fanotify_add_new_mark(group, inode, NULL);
|
fsn_mark = fanotify_add_new_mark(group, connp,
|
||||||
|
FSNOTIFY_OBJ_TYPE_INODE);
|
||||||
if (IS_ERR(fsn_mark)) {
|
if (IS_ERR(fsn_mark)) {
|
||||||
mutex_unlock(&group->mark_mutex);
|
mutex_unlock(&group->mark_mutex);
|
||||||
return PTR_ERR(fsn_mark);
|
return PTR_ERR(fsn_mark);
|
||||||
|
@ -9,6 +9,16 @@
|
|||||||
|
|
||||||
#include "../mount.h"
|
#include "../mount.h"
|
||||||
|
|
||||||
|
static inline struct inode *fsnotify_obj_inode(fsnotify_connp_t *connp)
|
||||||
|
{
|
||||||
|
return container_of(connp, struct inode, i_fsnotify_marks);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct mount *fsnotify_obj_mount(fsnotify_connp_t *connp)
|
||||||
|
{
|
||||||
|
return container_of(connp, struct mount, mnt_fsnotify_marks);
|
||||||
|
}
|
||||||
|
|
||||||
/* destroy all events sitting in this groups notification queue */
|
/* destroy all events sitting in this groups notification queue */
|
||||||
extern void fsnotify_flush_notify(struct fsnotify_group *group);
|
extern void fsnotify_flush_notify(struct fsnotify_group *group);
|
||||||
|
|
||||||
|
@ -437,9 +437,9 @@ int fsnotify_compare_groups(struct fsnotify_group *a, struct fsnotify_group *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,
|
static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,
|
||||||
struct inode *inode,
|
unsigned int type)
|
||||||
struct vfsmount *mnt)
|
|
||||||
{
|
{
|
||||||
|
struct inode *inode = NULL;
|
||||||
struct fsnotify_mark_connector *conn;
|
struct fsnotify_mark_connector *conn;
|
||||||
|
|
||||||
conn = kmem_cache_alloc(fsnotify_mark_connector_cachep, GFP_KERNEL);
|
conn = kmem_cache_alloc(fsnotify_mark_connector_cachep, GFP_KERNEL);
|
||||||
@ -447,13 +447,11 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
spin_lock_init(&conn->lock);
|
spin_lock_init(&conn->lock);
|
||||||
INIT_HLIST_HEAD(&conn->list);
|
INIT_HLIST_HEAD(&conn->list);
|
||||||
if (inode) {
|
conn->type = type;
|
||||||
conn->type = FSNOTIFY_OBJ_TYPE_INODE;
|
if (conn->type == FSNOTIFY_OBJ_TYPE_INODE)
|
||||||
conn->inode = igrab(inode);
|
inode = conn->inode = igrab(fsnotify_obj_inode(connp));
|
||||||
} else {
|
else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT)
|
||||||
conn->type = FSNOTIFY_OBJ_TYPE_VFSMOUNT;
|
conn->mnt = &fsnotify_obj_mount(connp)->mnt;
|
||||||
conn->mnt = mnt;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* cmpxchg() provides the barrier so that readers of *connp can see
|
* cmpxchg() provides the barrier so that readers of *connp can see
|
||||||
* only initialized structure
|
* only initialized structure
|
||||||
@ -502,27 +500,22 @@ out:
|
|||||||
* priority, highest number first, and then by the group's location in memory.
|
* priority, highest number first, and then by the group's location in memory.
|
||||||
*/
|
*/
|
||||||
static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
|
static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
|
||||||
struct inode *inode, struct vfsmount *mnt,
|
fsnotify_connp_t *connp, unsigned int type,
|
||||||
int allow_dups)
|
int allow_dups)
|
||||||
{
|
{
|
||||||
struct fsnotify_mark *lmark, *last = NULL;
|
struct fsnotify_mark *lmark, *last = NULL;
|
||||||
struct fsnotify_mark_connector *conn;
|
struct fsnotify_mark_connector *conn;
|
||||||
fsnotify_connp_t *connp;
|
|
||||||
int cmp;
|
int cmp;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (WARN_ON(!inode && !mnt))
|
if (WARN_ON(!fsnotify_valid_obj_type(type)))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (inode)
|
|
||||||
connp = &inode->i_fsnotify_marks;
|
|
||||||
else
|
|
||||||
connp = &real_mount(mnt)->mnt_fsnotify_marks;
|
|
||||||
restart:
|
restart:
|
||||||
spin_lock(&mark->lock);
|
spin_lock(&mark->lock);
|
||||||
conn = fsnotify_grab_connector(connp);
|
conn = fsnotify_grab_connector(connp);
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
spin_unlock(&mark->lock);
|
spin_unlock(&mark->lock);
|
||||||
err = fsnotify_attach_connector_to_object(connp, inode, mnt);
|
err = fsnotify_attach_connector_to_object(connp, type);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
goto restart;
|
goto restart;
|
||||||
@ -568,14 +561,13 @@ out_err:
|
|||||||
* These marks may be used for the fsnotify backend to determine which
|
* These marks may be used for the fsnotify backend to determine which
|
||||||
* event types should be delivered to which group.
|
* event types should be delivered to which group.
|
||||||
*/
|
*/
|
||||||
int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct inode *inode,
|
int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
|
||||||
struct vfsmount *mnt, int allow_dups)
|
fsnotify_connp_t *connp, unsigned int type,
|
||||||
|
int allow_dups)
|
||||||
{
|
{
|
||||||
struct fsnotify_group *group = mark->group;
|
struct fsnotify_group *group = mark->group;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
BUG_ON(inode && mnt);
|
|
||||||
BUG_ON(!inode && !mnt);
|
|
||||||
BUG_ON(!mutex_is_locked(&group->mark_mutex));
|
BUG_ON(!mutex_is_locked(&group->mark_mutex));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -592,7 +584,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct inode *inode,
|
|||||||
fsnotify_get_mark(mark); /* for g_list */
|
fsnotify_get_mark(mark); /* for g_list */
|
||||||
spin_unlock(&mark->lock);
|
spin_unlock(&mark->lock);
|
||||||
|
|
||||||
ret = fsnotify_add_mark_list(mark, inode, mnt, allow_dups);
|
ret = fsnotify_add_mark_list(mark, connp, type, allow_dups);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
@ -612,14 +604,14 @@ err:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode,
|
int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp,
|
||||||
struct vfsmount *mnt, int allow_dups)
|
unsigned int type, int allow_dups)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct fsnotify_group *group = mark->group;
|
struct fsnotify_group *group = mark->group;
|
||||||
|
|
||||||
mutex_lock(&group->mark_mutex);
|
mutex_lock(&group->mark_mutex);
|
||||||
ret = fsnotify_add_mark_locked(mark, inode, mnt, allow_dups);
|
ret = fsnotify_add_mark_locked(mark, connp, type, allow_dups);
|
||||||
mutex_unlock(&group->mark_mutex);
|
mutex_unlock(&group->mark_mutex);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -210,6 +210,11 @@ enum fsnotify_obj_type {
|
|||||||
#define FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL (1U << FSNOTIFY_OBJ_TYPE_VFSMOUNT)
|
#define FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL (1U << FSNOTIFY_OBJ_TYPE_VFSMOUNT)
|
||||||
#define FSNOTIFY_OBJ_ALL_TYPES_MASK ((1U << FSNOTIFY_OBJ_TYPE_COUNT) - 1)
|
#define FSNOTIFY_OBJ_ALL_TYPES_MASK ((1U << FSNOTIFY_OBJ_TYPE_COUNT) - 1)
|
||||||
|
|
||||||
|
static inline bool fsnotify_valid_obj_type(unsigned int type)
|
||||||
|
{
|
||||||
|
return (type < FSNOTIFY_OBJ_TYPE_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
struct fsnotify_iter_info {
|
struct fsnotify_iter_info {
|
||||||
struct fsnotify_mark *marks[FSNOTIFY_OBJ_TYPE_COUNT];
|
struct fsnotify_mark *marks[FSNOTIFY_OBJ_TYPE_COUNT];
|
||||||
unsigned int report_mask;
|
unsigned int report_mask;
|
||||||
@ -398,24 +403,27 @@ extern void fsnotify_init_mark(struct fsnotify_mark *mark,
|
|||||||
/* Find mark belonging to given group in the list of marks */
|
/* Find mark belonging to given group in the list of marks */
|
||||||
extern struct fsnotify_mark *fsnotify_find_mark(fsnotify_connp_t *connp,
|
extern struct fsnotify_mark *fsnotify_find_mark(fsnotify_connp_t *connp,
|
||||||
struct fsnotify_group *group);
|
struct fsnotify_group *group);
|
||||||
/* attach the mark to the inode or vfsmount */
|
/* attach the mark to the object */
|
||||||
extern int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode,
|
extern int fsnotify_add_mark(struct fsnotify_mark *mark,
|
||||||
struct vfsmount *mnt, int allow_dups);
|
fsnotify_connp_t *connp, unsigned int type,
|
||||||
|
int allow_dups);
|
||||||
extern int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
|
extern int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
|
||||||
struct inode *inode, struct vfsmount *mnt,
|
fsnotify_connp_t *connp, unsigned int type,
|
||||||
int allow_dups);
|
int allow_dups);
|
||||||
/* attach the mark to the inode */
|
/* attach the mark to the inode */
|
||||||
static inline int fsnotify_add_inode_mark(struct fsnotify_mark *mark,
|
static inline int fsnotify_add_inode_mark(struct fsnotify_mark *mark,
|
||||||
struct inode *inode,
|
struct inode *inode,
|
||||||
int allow_dups)
|
int allow_dups)
|
||||||
{
|
{
|
||||||
return fsnotify_add_mark(mark, inode, NULL, allow_dups);
|
return fsnotify_add_mark(mark, &inode->i_fsnotify_marks,
|
||||||
|
FSNOTIFY_OBJ_TYPE_INODE, allow_dups);
|
||||||
}
|
}
|
||||||
static inline int fsnotify_add_inode_mark_locked(struct fsnotify_mark *mark,
|
static inline int fsnotify_add_inode_mark_locked(struct fsnotify_mark *mark,
|
||||||
struct inode *inode,
|
struct inode *inode,
|
||||||
int allow_dups)
|
int allow_dups)
|
||||||
{
|
{
|
||||||
return fsnotify_add_mark_locked(mark, inode, NULL, allow_dups);
|
return fsnotify_add_mark_locked(mark, &inode->i_fsnotify_marks,
|
||||||
|
FSNOTIFY_OBJ_TYPE_INODE, allow_dups);
|
||||||
}
|
}
|
||||||
/* given a group and a mark, flag mark to be freed when all references are dropped */
|
/* given a group and a mark, flag mark to be freed when all references are dropped */
|
||||||
extern void fsnotify_destroy_mark(struct fsnotify_mark *mark,
|
extern void fsnotify_destroy_mark(struct fsnotify_mark *mark,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user