Skip to content

Commit 3ac70bf

Browse files
amir73iljankara
authored andcommitted
fsnotify: add helper to get mask from connector
Use a helper to get the mask from the object (i.e. i_fsnotify_mask) to generalize code of add/remove inode/vfsmount mark. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 36f10f5 commit 3ac70bf

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group,
542542

543543
removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags,
544544
&destroy_mark);
545-
if (removed & real_mount(mnt)->mnt_fsnotify_mask)
546-
fsnotify_recalc_mask(real_mount(mnt)->mnt_fsnotify_marks);
545+
if (removed & fsnotify_conn_mask(fsn_mark->connector))
546+
fsnotify_recalc_mask(fsn_mark->connector);
547547
if (destroy_mark)
548548
fsnotify_detach_mark(fsn_mark);
549549
mutex_unlock(&group->mark_mutex);
@@ -571,8 +571,8 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group,
571571

572572
removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags,
573573
&destroy_mark);
574-
if (removed & inode->i_fsnotify_mask)
575-
fsnotify_recalc_mask(inode->i_fsnotify_marks);
574+
if (removed & fsnotify_conn_mask(fsn_mark->connector))
575+
fsnotify_recalc_mask(fsn_mark->connector);
576576
if (destroy_mark)
577577
fsnotify_detach_mark(fsn_mark);
578578
mutex_unlock(&group->mark_mutex);
@@ -658,8 +658,8 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group,
658658
}
659659
}
660660
added = fanotify_mark_add_to_mask(fsn_mark, mask, flags);
661-
if (added & ~real_mount(mnt)->mnt_fsnotify_mask)
662-
fsnotify_recalc_mask(real_mount(mnt)->mnt_fsnotify_marks);
661+
if (added & ~fsnotify_conn_mask(fsn_mark->connector))
662+
fsnotify_recalc_mask(fsn_mark->connector);
663663
mutex_unlock(&group->mark_mutex);
664664

665665
fsnotify_put_mark(fsn_mark);
@@ -697,8 +697,8 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
697697
}
698698
}
699699
added = fanotify_mark_add_to_mask(fsn_mark, mask, flags);
700-
if (added & ~inode->i_fsnotify_mask)
701-
fsnotify_recalc_mask(inode->i_fsnotify_marks);
700+
if (added & ~fsnotify_conn_mask(fsn_mark->connector))
701+
fsnotify_recalc_mask(fsn_mark->connector);
702702
mutex_unlock(&group->mark_mutex);
703703

704704
fsnotify_put_mark(fsn_mark);

fs/notify/mark.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,23 @@ void fsnotify_get_mark(struct fsnotify_mark *mark)
109109
refcount_inc(&mark->refcnt);
110110
}
111111

112+
static __u32 *fsnotify_conn_mask_p(struct fsnotify_mark_connector *conn)
113+
{
114+
if (conn->type == FSNOTIFY_OBJ_TYPE_INODE)
115+
return &fsnotify_conn_inode(conn)->i_fsnotify_mask;
116+
else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT)
117+
return &fsnotify_conn_mount(conn)->mnt_fsnotify_mask;
118+
return NULL;
119+
}
120+
121+
__u32 fsnotify_conn_mask(struct fsnotify_mark_connector *conn)
122+
{
123+
if (WARN_ON(!fsnotify_valid_obj_type(conn->type)))
124+
return 0;
125+
126+
return *fsnotify_conn_mask_p(conn);
127+
}
128+
112129
static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)
113130
{
114131
u32 new_mask = 0;
@@ -119,10 +136,10 @@ static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)
119136
if (mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED)
120137
new_mask |= mark->mask;
121138
}
122-
if (conn->type == FSNOTIFY_OBJ_TYPE_INODE)
123-
fsnotify_conn_inode(conn)->i_fsnotify_mask = new_mask;
124-
else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT)
125-
fsnotify_conn_mount(conn)->mnt_fsnotify_mask = new_mask;
139+
if (WARN_ON(!fsnotify_valid_obj_type(conn->type)))
140+
return;
141+
142+
*fsnotify_conn_mask_p(conn) = new_mask;
126143
}
127144

128145
/*

include/linux/fsnotify_backend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ extern struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group
401401

402402
/* functions used to manipulate the marks attached to inodes */
403403

404+
/* Get mask of events for a list of marks */
405+
extern __u32 fsnotify_conn_mask(struct fsnotify_mark_connector *conn);
404406
/* Calculate mask of events for a list of marks */
405407
extern void fsnotify_recalc_mask(struct fsnotify_mark_connector *conn);
406408
extern void fsnotify_init_mark(struct fsnotify_mark *mark,

0 commit comments

Comments
 (0)