Skip to content

Commit bcae32c

Browse files
committed
eventfs: Move taking of inode_lock into dcache_dir_open_wrapper()
The both create_file_dentry() and create_dir_dentry() takes a boolean parameter "lookup", as on lookup the inode_lock should already be taken, but for dcache_dir_open_wrapper() it is not taken. There's no reason that the dcache_dir_open_wrapper() can't take the inode_lock before calling these functions. In fact, it's better if it does, as the lock can be held throughout both directory and file creations. This also simplifies the code, and possibly prevents unexpected race conditions when the lock is released. Link: https://lkml.kernel.org/r/[email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Andrew Morton <[email protected]> Fixes: 5790b1f ("eventfs: Remove eventfs_file and just use eventfs_inode") Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 4763d63 commit bcae32c

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

fs/tracefs/event_inode.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,8 @@ create_file_dentry(struct eventfs_inode *ei, int idx,
347347

348348
mutex_unlock(&eventfs_mutex);
349349

350-
/* The lookup already has the parent->d_inode locked */
351-
if (!lookup)
352-
inode_lock(parent->d_inode);
353-
354350
dentry = create_file(name, mode, attr, parent, data, fops);
355351

356-
if (!lookup)
357-
inode_unlock(parent->d_inode);
358-
359352
mutex_lock(&eventfs_mutex);
360353

361354
if (IS_ERR_OR_NULL(dentry)) {
@@ -453,15 +446,8 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei,
453446
}
454447
mutex_unlock(&eventfs_mutex);
455448

456-
/* The lookup already has the parent->d_inode locked */
457-
if (!lookup)
458-
inode_lock(parent->d_inode);
459-
460449
dentry = create_dir(ei, parent);
461450

462-
if (!lookup)
463-
inode_unlock(parent->d_inode);
464-
465451
mutex_lock(&eventfs_mutex);
466452

467453
if (IS_ERR_OR_NULL(dentry) && !ei->is_freed) {
@@ -693,6 +679,7 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
693679
return -ENOMEM;
694680
}
695681

682+
inode_lock(parent->d_inode);
696683
list_for_each_entry_srcu(ei_child, &ei->children, list,
697684
srcu_read_lock_held(&eventfs_srcu)) {
698685
d = create_dir_dentry(ei, ei_child, parent, false);
@@ -725,6 +712,7 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
725712
cnt++;
726713
}
727714
}
715+
inode_unlock(parent->d_inode);
728716
srcu_read_unlock(&eventfs_srcu, idx);
729717
ret = dcache_dir_open(inode, file);
730718

0 commit comments

Comments
 (0)