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>

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