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/20231121231112.528544825@goodmis.org

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode")
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+2 -14
+2 -14
fs/tracefs/event_inode.c
··· 347 348 mutex_unlock(&eventfs_mutex); 349 350 - /* The lookup already has the parent->d_inode locked */ 351 - if (!lookup) 352 - inode_lock(parent->d_inode); 353 - 354 dentry = create_file(name, mode, attr, parent, data, fops); 355 - 356 - if (!lookup) 357 - inode_unlock(parent->d_inode); 358 359 mutex_lock(&eventfs_mutex); 360 ··· 446 } 447 mutex_unlock(&eventfs_mutex); 448 449 - /* The lookup already has the parent->d_inode locked */ 450 - if (!lookup) 451 - inode_lock(parent->d_inode); 452 - 453 dentry = create_dir(ei, parent); 454 - 455 - if (!lookup) 456 - inode_unlock(parent->d_inode); 457 458 mutex_lock(&eventfs_mutex); 459 ··· 679 return -ENOMEM; 680 } 681 682 list_for_each_entry_srcu(ei_child, &ei->children, list, 683 srcu_read_lock_held(&eventfs_srcu)) { 684 d = create_dir_dentry(ei, ei_child, parent, false); ··· 712 cnt++; 713 } 714 } 715 srcu_read_unlock(&eventfs_srcu, idx); 716 ret = dcache_dir_open(inode, file); 717
··· 347 348 mutex_unlock(&eventfs_mutex); 349 350 dentry = create_file(name, mode, attr, parent, data, fops); 351 352 mutex_lock(&eventfs_mutex); 353 ··· 453 } 454 mutex_unlock(&eventfs_mutex); 455 456 dentry = create_dir(ei, parent); 457 458 mutex_lock(&eventfs_mutex); 459 ··· 693 return -ENOMEM; 694 } 695 696 + inode_lock(parent->d_inode); 697 list_for_each_entry_srcu(ei_child, &ei->children, list, 698 srcu_read_lock_held(&eventfs_srcu)) { 699 d = create_dir_dentry(ei, ei_child, parent, false); ··· 725 cnt++; 726 } 727 } 728 + inode_unlock(parent->d_inode); 729 srcu_read_unlock(&eventfs_srcu, idx); 730 ret = dcache_dir_open(inode, file); 731