[PATCH v6 06/12] vfs: lookup_open(): lock the parent as I_MUTEX_PARENT

From: Jori Koolstra

Date: Sun Sep 13 2026 - 14:51:09 EST


lookup_open() takes the parent directory's i_rwsem with inode_lock(),
that is, in the I_MUTEX_NORMAL class, before creating the last
component. Every other VFS path that locks a directory in order to
create something in it goes through start_dirop() and friends, which
use inode_lock_nested(dir, I_MUTEX_PARENT).

Lock the parent as I_MUTEX_PARENT here too, so that lookup_open()
matches the rest of the VFS before it starts calling ->mkdir(), which
until now was only ever reached with the parent held that way.

No functional change intended.

Signed-off-by: Jori Koolstra <jkoolstra@xxxxxxxxx>
---
fs/namei.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/namei.c b/fs/namei.c
index 90c8be0257be..0efd395a1a65 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4482,7 +4482,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
*/
}
if (open_flag & O_CREAT)
- inode_lock(dir_inode);
+ inode_lock_nested(dir_inode, I_MUTEX_PARENT);
else
inode_lock_shared(dir_inode);

--
2.55.0