diff options
author | Amir Goldstein <amir73il@gmail.com> | 2018-06-23 10:54:49 -0400 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2018-06-27 07:45:05 -0400 |
commit | 36f10f55ff1d2867bfc48ed898a9cc0dc6b49dd2 (patch) | |
tree | 0b7a840c5c8e0b2bd44aeca2c21a144b25d89457 | |
parent | b812a9f5896379b6cff2ac168ddb5b89037d8e78 (diff) |
fsnotify: let connector point to an abstract object
Make the code to attach/detach a connector to object more generic
by letting the fsnotify connector point to an abstract fsnotify_connp_t.
Code that needs to dereference an inode or mount object now uses the
helpers fsnotify_conn_{inode,mount}.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r-- | fs/notify/fdinfo.c | 8 | ||||
-rw-r--r-- | fs/notify/fsnotify.h | 10 | ||||
-rw-r--r-- | fs/notify/mark.c | 32 | ||||
-rw-r--r-- | include/linux/fsnotify_backend.h | 15 | ||||
-rw-r--r-- | kernel/audit_tree.c | 17 |
5 files changed, 45 insertions, 37 deletions
diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c index 10aac1942c9f..86fcf5814279 100644 --- a/fs/notify/fdinfo.c +++ b/fs/notify/fdinfo.c | |||
@@ -15,7 +15,7 @@ | |||
15 | #include <linux/exportfs.h> | 15 | #include <linux/exportfs.h> |
16 | 16 | ||
17 | #include "inotify/inotify.h" | 17 | #include "inotify/inotify.h" |
18 | #include "../fs/mount.h" | 18 | #include "fsnotify.h" |
19 | 19 | ||
20 | #if defined(CONFIG_PROC_FS) | 20 | #if defined(CONFIG_PROC_FS) |
21 | 21 | ||
@@ -81,7 +81,7 @@ static void inotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) | |||
81 | return; | 81 | return; |
82 | 82 | ||
83 | inode_mark = container_of(mark, struct inotify_inode_mark, fsn_mark); | 83 | inode_mark = container_of(mark, struct inotify_inode_mark, fsn_mark); |
84 | inode = igrab(mark->connector->inode); | 84 | inode = igrab(fsnotify_conn_inode(mark->connector)); |
85 | if (inode) { | 85 | if (inode) { |
86 | /* | 86 | /* |
87 | * IN_ALL_EVENTS represents all of the mask bits | 87 | * IN_ALL_EVENTS represents all of the mask bits |
@@ -117,7 +117,7 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) | |||
117 | mflags |= FAN_MARK_IGNORED_SURV_MODIFY; | 117 | mflags |= FAN_MARK_IGNORED_SURV_MODIFY; |
118 | 118 | ||
119 | if (mark->connector->type == FSNOTIFY_OBJ_TYPE_INODE) { | 119 | if (mark->connector->type == FSNOTIFY_OBJ_TYPE_INODE) { |
120 | inode = igrab(mark->connector->inode); | 120 | inode = igrab(fsnotify_conn_inode(mark->connector)); |
121 | if (!inode) | 121 | if (!inode) |
122 | return; | 122 | return; |
123 | seq_printf(m, "fanotify ino:%lx sdev:%x mflags:%x mask:%x ignored_mask:%x ", | 123 | seq_printf(m, "fanotify ino:%lx sdev:%x mflags:%x mask:%x ignored_mask:%x ", |
@@ -127,7 +127,7 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) | |||
127 | seq_putc(m, '\n'); | 127 | seq_putc(m, '\n'); |
128 | iput(inode); | 128 | iput(inode); |
129 | } else if (mark->connector->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { | 129 | } else if (mark->connector->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { |
130 | struct mount *mnt = real_mount(mark->connector->mnt); | 130 | struct mount *mnt = fsnotify_conn_mount(mark->connector); |
131 | 131 | ||
132 | seq_printf(m, "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x\n", | 132 | seq_printf(m, "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x\n", |
133 | mnt->mnt_id, mflags, mark->mask, mark->ignored_mask); | 133 | mnt->mnt_id, mflags, mark->mask, mark->ignored_mask); |
diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h index caeee042d1cc..7902653dd577 100644 --- a/fs/notify/fsnotify.h +++ b/fs/notify/fsnotify.h | |||
@@ -9,14 +9,16 @@ | |||
9 | 9 | ||
10 | #include "../mount.h" | 10 | #include "../mount.h" |
11 | 11 | ||
12 | static inline struct inode *fsnotify_obj_inode(fsnotify_connp_t *connp) | 12 | static inline struct inode *fsnotify_conn_inode( |
13 | struct fsnotify_mark_connector *conn) | ||
13 | { | 14 | { |
14 | return container_of(connp, struct inode, i_fsnotify_marks); | 15 | return container_of(conn->obj, struct inode, i_fsnotify_marks); |
15 | } | 16 | } |
16 | 17 | ||
17 | static inline struct mount *fsnotify_obj_mount(fsnotify_connp_t *connp) | 18 | static inline struct mount *fsnotify_conn_mount( |
19 | struct fsnotify_mark_connector *conn) | ||
18 | { | 20 | { |
19 | return container_of(connp, struct mount, mnt_fsnotify_marks); | 21 | return container_of(conn->obj, struct mount, mnt_fsnotify_marks); |
20 | } | 22 | } |
21 | 23 | ||
22 | /* destroy all events sitting in this groups notification queue */ | 24 | /* destroy all events sitting in this groups notification queue */ |
diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 7abb73b5beba..959bc73aaae7 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c | |||
@@ -120,14 +120,14 @@ static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) | |||
120 | new_mask |= mark->mask; | 120 | new_mask |= mark->mask; |
121 | } | 121 | } |
122 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) | 122 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) |
123 | conn->inode->i_fsnotify_mask = new_mask; | 123 | fsnotify_conn_inode(conn)->i_fsnotify_mask = new_mask; |
124 | else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) | 124 | else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) |
125 | real_mount(conn->mnt)->mnt_fsnotify_mask = new_mask; | 125 | fsnotify_conn_mount(conn)->mnt_fsnotify_mask = new_mask; |
126 | } | 126 | } |
127 | 127 | ||
128 | /* | 128 | /* |
129 | * Calculate mask of events for a list of marks. The caller must make sure | 129 | * Calculate mask of events for a list of marks. The caller must make sure |
130 | * connector and connector->inode cannot disappear under us. Callers achieve | 130 | * connector and connector->obj cannot disappear under us. Callers achieve |
131 | * this by holding a mark->lock or mark->group->mark_mutex for a mark on this | 131 | * this by holding a mark->lock or mark->group->mark_mutex for a mark on this |
132 | * list. | 132 | * list. |
133 | */ | 133 | */ |
@@ -140,7 +140,8 @@ void fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) | |||
140 | __fsnotify_recalc_mask(conn); | 140 | __fsnotify_recalc_mask(conn); |
141 | spin_unlock(&conn->lock); | 141 | spin_unlock(&conn->lock); |
142 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) | 142 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) |
143 | __fsnotify_update_child_dentry_flags(conn->inode); | 143 | __fsnotify_update_child_dentry_flags( |
144 | fsnotify_conn_inode(conn)); | ||
144 | } | 145 | } |
145 | 146 | ||
146 | /* Free all connectors queued for freeing once SRCU period ends */ | 147 | /* Free all connectors queued for freeing once SRCU period ends */ |
@@ -166,20 +167,20 @@ static struct inode *fsnotify_detach_connector_from_object( | |||
166 | { | 167 | { |
167 | struct inode *inode = NULL; | 168 | struct inode *inode = NULL; |
168 | 169 | ||
170 | if (conn->type == FSNOTIFY_OBJ_TYPE_DETACHED) | ||
171 | return NULL; | ||
172 | |||
169 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) { | 173 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) { |
170 | inode = conn->inode; | 174 | inode = fsnotify_conn_inode(conn); |
171 | rcu_assign_pointer(inode->i_fsnotify_marks, NULL); | ||
172 | inode->i_fsnotify_mask = 0; | 175 | inode->i_fsnotify_mask = 0; |
173 | conn->inode = NULL; | ||
174 | conn->type = FSNOTIFY_OBJ_TYPE_DETACHED; | ||
175 | } else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { | 176 | } else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { |
176 | rcu_assign_pointer(real_mount(conn->mnt)->mnt_fsnotify_marks, | 177 | fsnotify_conn_mount(conn)->mnt_fsnotify_mask = 0; |
177 | NULL); | ||
178 | real_mount(conn->mnt)->mnt_fsnotify_mask = 0; | ||
179 | conn->mnt = NULL; | ||
180 | conn->type = FSNOTIFY_OBJ_TYPE_DETACHED; | ||
181 | } | 178 | } |
182 | 179 | ||
180 | rcu_assign_pointer(*(conn->obj), NULL); | ||
181 | conn->obj = NULL; | ||
182 | conn->type = FSNOTIFY_OBJ_TYPE_DETACHED; | ||
183 | |||
183 | return inode; | 184 | return inode; |
184 | } | 185 | } |
185 | 186 | ||
@@ -448,10 +449,9 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, | |||
448 | spin_lock_init(&conn->lock); | 449 | spin_lock_init(&conn->lock); |
449 | INIT_HLIST_HEAD(&conn->list); | 450 | INIT_HLIST_HEAD(&conn->list); |
450 | conn->type = type; | 451 | conn->type = type; |
452 | conn->obj = connp; | ||
451 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) | 453 | if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) |
452 | inode = conn->inode = igrab(fsnotify_obj_inode(connp)); | 454 | inode = igrab(fsnotify_conn_inode(conn)); |
453 | else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) | ||
454 | conn->mnt = &fsnotify_obj_mount(connp)->mnt; | ||
455 | /* | 455 | /* |
456 | * cmpxchg() provides the barrier so that readers of *connp can see | 456 | * cmpxchg() provides the barrier so that readers of *connp can see |
457 | * only initialized structure | 457 | * only initialized structure |
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 8efb8663453d..381cfb0e67fa 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h | |||
@@ -256,6 +256,13 @@ FSNOTIFY_ITER_FUNCS(vfsmount, VFSMOUNT) | |||
256 | for (type = 0; type < FSNOTIFY_OBJ_TYPE_COUNT; type++) | 256 | for (type = 0; type < FSNOTIFY_OBJ_TYPE_COUNT; type++) |
257 | 257 | ||
258 | /* | 258 | /* |
259 | * fsnotify_connp_t is what we embed in objects which connector can be attached | ||
260 | * to. fsnotify_connp_t * is how we refer from connector back to object. | ||
261 | */ | ||
262 | struct fsnotify_mark_connector; | ||
263 | typedef struct fsnotify_mark_connector __rcu *fsnotify_connp_t; | ||
264 | |||
265 | /* | ||
259 | * Inode / vfsmount point to this structure which tracks all marks attached to | 266 | * Inode / vfsmount point to this structure which tracks all marks attached to |
260 | * the inode / vfsmount. The reference to inode / vfsmount is held by this | 267 | * the inode / vfsmount. The reference to inode / vfsmount is held by this |
261 | * structure. We destroy this structure when there are no more marks attached | 268 | * structure. We destroy this structure when there are no more marks attached |
@@ -264,17 +271,15 @@ FSNOTIFY_ITER_FUNCS(vfsmount, VFSMOUNT) | |||
264 | struct fsnotify_mark_connector { | 271 | struct fsnotify_mark_connector { |
265 | spinlock_t lock; | 272 | spinlock_t lock; |
266 | unsigned int type; /* Type of object [lock] */ | 273 | unsigned int type; /* Type of object [lock] */ |
267 | union { /* Object pointer [lock] */ | 274 | union { |
268 | struct inode *inode; | 275 | /* Object pointer [lock] */ |
269 | struct vfsmount *mnt; | 276 | fsnotify_connp_t *obj; |
270 | /* Used listing heads to free after srcu period expires */ | 277 | /* Used listing heads to free after srcu period expires */ |
271 | struct fsnotify_mark_connector *destroy_next; | 278 | struct fsnotify_mark_connector *destroy_next; |
272 | }; | 279 | }; |
273 | struct hlist_head list; | 280 | struct hlist_head list; |
274 | }; | 281 | }; |
275 | 282 | ||
276 | typedef struct fsnotify_mark_connector __rcu *fsnotify_connp_t; | ||
277 | |||
278 | /* | 283 | /* |
279 | * A mark is simply an object attached to an in core inode which allows an | 284 | * A mark is simply an object attached to an in core inode which allows an |
280 | * fsnotify listener to indicate they are either no longer interested in events | 285 | * fsnotify listener to indicate they are either no longer interested in events |
diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c index c99ebaae5abc..02feef939560 100644 --- a/kernel/audit_tree.c +++ b/kernel/audit_tree.c | |||
@@ -168,7 +168,8 @@ static __cacheline_aligned_in_smp DEFINE_SPINLOCK(hash_lock); | |||
168 | /* Function to return search key in our hash from inode. */ | 168 | /* Function to return search key in our hash from inode. */ |
169 | static unsigned long inode_to_key(const struct inode *inode) | 169 | static unsigned long inode_to_key(const struct inode *inode) |
170 | { | 170 | { |
171 | return (unsigned long)inode; | 171 | /* Use address pointed to by connector->obj as the key */ |
172 | return (unsigned long)&inode->i_fsnotify_marks; | ||
172 | } | 173 | } |
173 | 174 | ||
174 | /* | 175 | /* |
@@ -183,7 +184,7 @@ static unsigned long chunk_to_key(struct audit_chunk *chunk) | |||
183 | */ | 184 | */ |
184 | if (WARN_ON_ONCE(!chunk->mark.connector)) | 185 | if (WARN_ON_ONCE(!chunk->mark.connector)) |
185 | return 0; | 186 | return 0; |
186 | return (unsigned long)chunk->mark.connector->inode; | 187 | return (unsigned long)chunk->mark.connector->obj; |
187 | } | 188 | } |
188 | 189 | ||
189 | static inline struct list_head *chunk_hash(unsigned long key) | 190 | static inline struct list_head *chunk_hash(unsigned long key) |
@@ -258,7 +259,7 @@ static void untag_chunk(struct node *p) | |||
258 | spin_lock(&entry->lock); | 259 | spin_lock(&entry->lock); |
259 | /* | 260 | /* |
260 | * mark_mutex protects mark from getting detached and thus also from | 261 | * mark_mutex protects mark from getting detached and thus also from |
261 | * mark->connector->inode getting NULL. | 262 | * mark->connector->obj getting NULL. |
262 | */ | 263 | */ |
263 | if (chunk->dead || !(entry->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) { | 264 | if (chunk->dead || !(entry->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) { |
264 | spin_unlock(&entry->lock); | 265 | spin_unlock(&entry->lock); |
@@ -288,8 +289,8 @@ static void untag_chunk(struct node *p) | |||
288 | if (!new) | 289 | if (!new) |
289 | goto Fallback; | 290 | goto Fallback; |
290 | 291 | ||
291 | if (fsnotify_add_inode_mark_locked(&new->mark, entry->connector->inode, | 292 | if (fsnotify_add_mark_locked(&new->mark, entry->connector->obj, |
292 | 1)) { | 293 | FSNOTIFY_OBJ_TYPE_INODE, 1)) { |
293 | fsnotify_put_mark(&new->mark); | 294 | fsnotify_put_mark(&new->mark); |
294 | goto Fallback; | 295 | goto Fallback; |
295 | } | 296 | } |
@@ -423,7 +424,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) | |||
423 | spin_lock(&old_entry->lock); | 424 | spin_lock(&old_entry->lock); |
424 | /* | 425 | /* |
425 | * mark_mutex protects mark from getting detached and thus also from | 426 | * mark_mutex protects mark from getting detached and thus also from |
426 | * mark->connector->inode getting NULL. | 427 | * mark->connector->obj getting NULL. |
427 | */ | 428 | */ |
428 | if (!(old_entry->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) { | 429 | if (!(old_entry->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) { |
429 | /* old_entry is being shot, lets just lie */ | 430 | /* old_entry is being shot, lets just lie */ |
@@ -434,8 +435,8 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) | |||
434 | return -ENOENT; | 435 | return -ENOENT; |
435 | } | 436 | } |
436 | 437 | ||
437 | if (fsnotify_add_inode_mark_locked(chunk_entry, | 438 | if (fsnotify_add_mark_locked(chunk_entry, old_entry->connector->obj, |
438 | old_entry->connector->inode, 1)) { | 439 | FSNOTIFY_OBJ_TYPE_INODE, 1)) { |
439 | spin_unlock(&old_entry->lock); | 440 | spin_unlock(&old_entry->lock); |
440 | mutex_unlock(&old_entry->group->mark_mutex); | 441 | mutex_unlock(&old_entry->group->mark_mutex); |
441 | fsnotify_put_mark(chunk_entry); | 442 | fsnotify_put_mark(chunk_entry); |