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: 5790b1fb ("eventfs: Remove eventfs_file and just use eventfs_inode")
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent 4763d635
...@@ -347,15 +347,8 @@ create_file_dentry(struct eventfs_inode *ei, int idx, ...@@ -347,15 +347,8 @@ create_file_dentry(struct eventfs_inode *ei, int idx,
mutex_unlock(&eventfs_mutex); mutex_unlock(&eventfs_mutex);
/* The lookup already has the parent->d_inode locked */
if (!lookup)
inode_lock(parent->d_inode);
dentry = create_file(name, mode, attr, parent, data, fops); dentry = create_file(name, mode, attr, parent, data, fops);
if (!lookup)
inode_unlock(parent->d_inode);
mutex_lock(&eventfs_mutex); mutex_lock(&eventfs_mutex);
if (IS_ERR_OR_NULL(dentry)) { if (IS_ERR_OR_NULL(dentry)) {
...@@ -453,15 +446,8 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, ...@@ -453,15 +446,8 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei,
} }
mutex_unlock(&eventfs_mutex); mutex_unlock(&eventfs_mutex);
/* The lookup already has the parent->d_inode locked */
if (!lookup)
inode_lock(parent->d_inode);
dentry = create_dir(ei, parent); dentry = create_dir(ei, parent);
if (!lookup)
inode_unlock(parent->d_inode);
mutex_lock(&eventfs_mutex); mutex_lock(&eventfs_mutex);
if (IS_ERR_OR_NULL(dentry) && !ei->is_freed) { 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) ...@@ -693,6 +679,7 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
return -ENOMEM; return -ENOMEM;
} }
inode_lock(parent->d_inode);
list_for_each_entry_srcu(ei_child, &ei->children, list, list_for_each_entry_srcu(ei_child, &ei->children, list,
srcu_read_lock_held(&eventfs_srcu)) { srcu_read_lock_held(&eventfs_srcu)) {
d = create_dir_dentry(ei, ei_child, parent, false); 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) ...@@ -725,6 +712,7 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
cnt++; cnt++;
} }
} }
inode_unlock(parent->d_inode);
srcu_read_unlock(&eventfs_srcu, idx); srcu_read_unlock(&eventfs_srcu, idx);
ret = dcache_dir_open(inode, file); ret = dcache_dir_open(inode, file);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment