diff options
author | Miklos Szeredi <mszeredi@redhat.com> | 2017-10-30 16:14:56 -0400 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2017-10-31 12:54:56 -0400 |
commit | 3427ce7155412341aeb635c22c3ca2c2c9d1a978 (patch) | |
tree | fda47c368714c1737251aa4b94ad5697f588cf45 | |
parent | f37650f1c7c71cf5180b43229d13b421d81e7170 (diff) |
fsnotify: clean up fsnotify()
Use helpers to get first and next marks from connector.
Also get rid of inode_node/vfsmount_node local variables, which just refers
to the same objects as iter_info. There was an srcu_dereference() for
foo_node, but that's completely superfluous since we've already done it
when obtaining foo_node.
Also get rid of inode_group/vfsmount_group local variables; checking
against non-NULL for these is the same as checking against non-NULL
inode_mark/vfsmount_mark.
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r-- | fs/notify/fsnotify.c | 105 |
1 files changed, 45 insertions, 60 deletions
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 074716293829..81d8959b6aef 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c | |||
@@ -243,6 +243,29 @@ static int send_to_group(struct inode *to_tell, | |||
243 | file_name, cookie, iter_info); | 243 | file_name, cookie, iter_info); |
244 | } | 244 | } |
245 | 245 | ||
246 | static struct fsnotify_mark *fsnotify_first_mark(struct fsnotify_mark_connector **connp) | ||
247 | { | ||
248 | struct fsnotify_mark_connector *conn; | ||
249 | struct hlist_node *node = NULL; | ||
250 | |||
251 | conn = srcu_dereference(*connp, &fsnotify_mark_srcu); | ||
252 | if (conn) | ||
253 | node = srcu_dereference(conn->list.first, &fsnotify_mark_srcu); | ||
254 | |||
255 | return hlist_entry_safe(node, struct fsnotify_mark, obj_list); | ||
256 | } | ||
257 | |||
258 | static struct fsnotify_mark *fsnotify_next_mark(struct fsnotify_mark *mark) | ||
259 | { | ||
260 | struct hlist_node *node = NULL; | ||
261 | |||
262 | if (mark) | ||
263 | node = srcu_dereference(mark->obj_list.next, | ||
264 | &fsnotify_mark_srcu); | ||
265 | |||
266 | return hlist_entry_safe(node, struct fsnotify_mark, obj_list); | ||
267 | } | ||
268 | |||
246 | /* | 269 | /* |
247 | * This is the main call to fsnotify. The VFS calls into hook specific functions | 270 | * This is the main call to fsnotify. The VFS calls into hook specific functions |
248 | * in linux/fsnotify.h. Those functions then in turn call here. Here will call | 271 | * in linux/fsnotify.h. Those functions then in turn call here. Here will call |
@@ -252,11 +275,7 @@ static int send_to_group(struct inode *to_tell, | |||
252 | int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, | 275 | int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, |
253 | const unsigned char *file_name, u32 cookie) | 276 | const unsigned char *file_name, u32 cookie) |
254 | { | 277 | { |
255 | struct hlist_node *inode_node = NULL, *vfsmount_node = NULL; | 278 | struct fsnotify_iter_info iter_info = {}; |
256 | struct fsnotify_mark *inode_mark = NULL, *vfsmount_mark = NULL; | ||
257 | struct fsnotify_group *inode_group, *vfsmount_group; | ||
258 | struct fsnotify_mark_connector *inode_conn, *vfsmount_conn; | ||
259 | struct fsnotify_iter_info iter_info; | ||
260 | struct mount *mnt; | 279 | struct mount *mnt; |
261 | int ret = 0; | 280 | int ret = 0; |
262 | /* global tests shouldn't care about events on child only the specific event */ | 281 | /* global tests shouldn't care about events on child only the specific event */ |
@@ -291,26 +310,16 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, | |||
291 | 310 | ||
292 | if ((mask & FS_MODIFY) || | 311 | if ((mask & FS_MODIFY) || |
293 | (test_mask & to_tell->i_fsnotify_mask)) { | 312 | (test_mask & to_tell->i_fsnotify_mask)) { |
294 | inode_conn = srcu_dereference(to_tell->i_fsnotify_marks, | 313 | iter_info.inode_mark = |
295 | &fsnotify_mark_srcu); | 314 | fsnotify_first_mark(&to_tell->i_fsnotify_marks); |
296 | if (inode_conn) | ||
297 | inode_node = srcu_dereference(inode_conn->list.first, | ||
298 | &fsnotify_mark_srcu); | ||
299 | } | 315 | } |
300 | 316 | ||
301 | if (mnt && ((mask & FS_MODIFY) || | 317 | if (mnt && ((mask & FS_MODIFY) || |
302 | (test_mask & mnt->mnt_fsnotify_mask))) { | 318 | (test_mask & mnt->mnt_fsnotify_mask))) { |
303 | inode_conn = srcu_dereference(to_tell->i_fsnotify_marks, | 319 | iter_info.inode_mark = |
304 | &fsnotify_mark_srcu); | 320 | fsnotify_first_mark(&to_tell->i_fsnotify_marks); |
305 | if (inode_conn) | 321 | iter_info.vfsmount_mark = |
306 | inode_node = srcu_dereference(inode_conn->list.first, | 322 | fsnotify_first_mark(&mnt->mnt_fsnotify_marks); |
307 | &fsnotify_mark_srcu); | ||
308 | vfsmount_conn = srcu_dereference(mnt->mnt_fsnotify_marks, | ||
309 | &fsnotify_mark_srcu); | ||
310 | if (vfsmount_conn) | ||
311 | vfsmount_node = srcu_dereference( | ||
312 | vfsmount_conn->list.first, | ||
313 | &fsnotify_mark_srcu); | ||
314 | } | 323 | } |
315 | 324 | ||
316 | /* | 325 | /* |
@@ -318,41 +327,17 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, | |||
318 | * ignore masks are properly reflected for mount mark notifications. | 327 | * ignore masks are properly reflected for mount mark notifications. |
319 | * That's why this traversal is so complicated... | 328 | * That's why this traversal is so complicated... |
320 | */ | 329 | */ |
321 | while (inode_node || vfsmount_node) { | 330 | while (iter_info.inode_mark || iter_info.vfsmount_mark) { |
322 | inode_group = NULL; | 331 | struct fsnotify_mark *inode_mark = iter_info.inode_mark; |
323 | inode_mark = NULL; | 332 | struct fsnotify_mark *vfsmount_mark = iter_info.vfsmount_mark; |
324 | vfsmount_group = NULL; | 333 | |
325 | vfsmount_mark = NULL; | 334 | if (inode_mark && vfsmount_mark) { |
326 | 335 | int cmp = fsnotify_compare_groups(inode_mark->group, | |
327 | if (inode_node) { | 336 | vfsmount_mark->group); |
328 | inode_mark = hlist_entry(srcu_dereference(inode_node, &fsnotify_mark_srcu), | 337 | if (cmp > 0) |
329 | struct fsnotify_mark, obj_list); | ||
330 | inode_group = inode_mark->group; | ||
331 | } | ||
332 | |||
333 | if (vfsmount_node) { | ||
334 | vfsmount_mark = hlist_entry(srcu_dereference(vfsmount_node, &fsnotify_mark_srcu), | ||
335 | struct fsnotify_mark, obj_list); | ||
336 | vfsmount_group = vfsmount_mark->group; | ||
337 | } | ||
338 | /* | ||
339 | * Need to protect both marks against freeing so that we can | ||
340 | * continue iteration from this place, regardless of which mark | ||
341 | * we actually happen to send an event for. | ||
342 | */ | ||
343 | iter_info.inode_mark = inode_mark; | ||
344 | iter_info.vfsmount_mark = vfsmount_mark; | ||
345 | |||
346 | if (inode_group && vfsmount_group) { | ||
347 | int cmp = fsnotify_compare_groups(inode_group, | ||
348 | vfsmount_group); | ||
349 | if (cmp > 0) { | ||
350 | inode_group = NULL; | ||
351 | inode_mark = NULL; | 338 | inode_mark = NULL; |
352 | } else if (cmp < 0) { | 339 | else if (cmp < 0) |
353 | vfsmount_group = NULL; | ||
354 | vfsmount_mark = NULL; | 340 | vfsmount_mark = NULL; |
355 | } | ||
356 | } | 341 | } |
357 | 342 | ||
358 | ret = send_to_group(to_tell, inode_mark, vfsmount_mark, mask, | 343 | ret = send_to_group(to_tell, inode_mark, vfsmount_mark, mask, |
@@ -362,12 +347,12 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, | |||
362 | if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS)) | 347 | if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS)) |
363 | goto out; | 348 | goto out; |
364 | 349 | ||
365 | if (inode_group) | 350 | if (inode_mark) |
366 | inode_node = srcu_dereference(inode_node->next, | 351 | iter_info.inode_mark = |
367 | &fsnotify_mark_srcu); | 352 | fsnotify_next_mark(iter_info.inode_mark); |
368 | if (vfsmount_group) | 353 | if (vfsmount_mark) |
369 | vfsmount_node = srcu_dereference(vfsmount_node->next, | 354 | iter_info.vfsmount_mark = |
370 | &fsnotify_mark_srcu); | 355 | fsnotify_next_mark(iter_info.vfsmount_mark); |
371 | } | 356 | } |
372 | ret = 0; | 357 | ret = 0; |
373 | out: | 358 | out: |