diff options
author | Amir Goldstein <amir73il@gmail.com> | 2018-06-23 10:54:50 -0400 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2018-06-27 07:45:07 -0400 |
commit | 3ac70bfcde812b1b97d8a88a832df59941fa293f (patch) | |
tree | 52dad7896f274af1f4e12fc87997994387e12333 | |
parent | 36f10f55ff1d2867bfc48ed898a9cc0dc6b49dd2 (diff) |
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>
-rw-r--r-- | fs/notify/fanotify/fanotify_user.c | 16 | ||||
-rw-r--r-- | fs/notify/mark.c | 25 | ||||
-rw-r--r-- | include/linux/fsnotify_backend.h | 2 |
3 files changed, 31 insertions, 12 deletions
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 81212b251189..3899ad177651 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c | |||
@@ -542,8 +542,8 @@ static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group, | |||
542 | 542 | ||
543 | removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags, | 543 | removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags, |
544 | &destroy_mark); | 544 | &destroy_mark); |
545 | if (removed & real_mount(mnt)->mnt_fsnotify_mask) | 545 | if (removed & fsnotify_conn_mask(fsn_mark->connector)) |
546 | fsnotify_recalc_mask(real_mount(mnt)->mnt_fsnotify_marks); | 546 | fsnotify_recalc_mask(fsn_mark->connector); |
547 | if (destroy_mark) | 547 | if (destroy_mark) |
548 | fsnotify_detach_mark(fsn_mark); | 548 | fsnotify_detach_mark(fsn_mark); |
549 | mutex_unlock(&group->mark_mutex); | 549 | mutex_unlock(&group->mark_mutex); |
@@ -571,8 +571,8 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group, | |||
571 | 571 | ||
572 | removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags, | 572 | removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags, |
573 | &destroy_mark); | 573 | &destroy_mark); |
574 | if (removed & inode->i_fsnotify_mask) | 574 | if (removed & fsnotify_conn_mask(fsn_mark->connector)) |
575 | fsnotify_recalc_mask(inode->i_fsnotify_marks); | 575 | fsnotify_recalc_mask(fsn_mark->connector); |
576 | if (destroy_mark) | 576 | if (destroy_mark) |
577 | fsnotify_detach_mark(fsn_mark); | 577 | fsnotify_detach_mark(fsn_mark); |
578 | mutex_unlock(&group->mark_mutex); | 578 | mutex_unlock(&group->mark_mutex); |
@@ -658,8 +658,8 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group, | |||
658 | } | 658 | } |
659 | } | 659 | } |
660 | added = fanotify_mark_add_to_mask(fsn_mark, mask, flags); | 660 | added = fanotify_mark_add_to_mask(fsn_mark, mask, flags); |
661 | if (added & ~real_mount(mnt)->mnt_fsnotify_mask) | 661 | if (added & ~fsnotify_conn_mask(fsn_mark->connector)) |
662 | fsnotify_recalc_mask(real_mount(mnt)->mnt_fsnotify_marks); | 662 | fsnotify_recalc_mask(fsn_mark->connector); |
663 | mutex_unlock(&group->mark_mutex); | 663 | mutex_unlock(&group->mark_mutex); |
664 | 664 | ||
665 | fsnotify_put_mark(fsn_mark); | 665 | fsnotify_put_mark(fsn_mark); |
@@ -697,8 +697,8 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group, | |||
697 | } | 697 | } |
698 | } | 698 | } |
699 | added = fanotify_mark_add_to_mask(fsn_mark, mask, flags); | 699 | added = fanotify_mark_add_to_mask(fsn_mark, mask, flags); |
700 | if (added & ~inode->i_fsnotify_mask) | 700 | if (added & ~fsnotify_conn_mask(fsn_mark->connector)) |
701 | fsnotify_recalc_mask(inode->i_fsnotify_marks); | 701 | fsnotify_recalc_mask(fsn_mark->connector); |
702 | mutex_unlock(&group->mark_mutex); | 702 | mutex_unlock(&group->mark_mutex); |
703 | 703 | ||
704 | fsnotify_put_mark(fsn_mark); | 704 | fsnotify_put_mark(fsn_mark); |
diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 959bc73aaae7..05506d60131c 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c | |||
@@ -109,6 +109,23 @@ void fsnotify_get_mark(struct fsnotify_mark *mark) | |||
109 | refcount_inc(&mark->refcnt); | 109 | refcount_inc(&mark->refcnt); |
110 | } | 110 | } |
111 | 111 | ||
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 | |||
112 | static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) | 129 | static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) |
113 | { | 130 | { |
114 | u32 new_mask = 0; | 131 | u32 new_mask = 0; |
@@ -119,10 +136,10 @@ static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) | |||
119 | if (mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED) | 136 | if (mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED) |
120 | new_mask |= mark->mask; | 137 | new_mask |= mark->mask; |
121 | } | 138 | } |
122 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) | 139 | if (WARN_ON(!fsnotify_valid_obj_type(conn->type))) |
123 | fsnotify_conn_inode(conn)->i_fsnotify_mask = new_mask; | 140 | return; |
124 | else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) | 141 | |
125 | fsnotify_conn_mount(conn)->mnt_fsnotify_mask = new_mask; | 142 | *fsnotify_conn_mask_p(conn) = new_mask; |
126 | } | 143 | } |
127 | 144 | ||
128 | /* | 145 | /* |
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 381cfb0e67fa..2b9b6f1ff5e0 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h | |||
@@ -401,6 +401,8 @@ extern struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group | |||
401 | 401 | ||
402 | /* functions used to manipulate the marks attached to inodes */ | 402 | /* functions used to manipulate the marks attached to inodes */ |
403 | 403 | ||
404 | /* Get mask of events for a list of marks */ | ||
405 | extern __u32 fsnotify_conn_mask(struct fsnotify_mark_connector *conn); | ||
404 | /* Calculate mask of events for a list of marks */ | 406 | /* Calculate mask of events for a list of marks */ |
405 | extern void fsnotify_recalc_mask(struct fsnotify_mark_connector *conn); | 407 | extern void fsnotify_recalc_mask(struct fsnotify_mark_connector *conn); |
406 | extern void fsnotify_init_mark(struct fsnotify_mark *mark, | 408 | extern void fsnotify_init_mark(struct fsnotify_mark *mark, |