Thread (16 messages) 16 messages, 2 authors, 8d ago

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

flat view
COOLING8d SUPERSEDED

From: Jori Koolstra <jkoolstra@xs4all.nl>
Date: 2026-10-16 14:37:15
Also in: linux-fsdevel, lkml
Subsystem: filesystems (vfs and infrastructure), the rest · Maintainers: Alexander Viro, Christian Brauner, Linus Torvalds

Status: Superseded by v8 (posted 2026-10-24). [go to v8]

Revision v7 (7 revisions archived).

Revisions (7)
  1. v6 re-posted go to this post
  2. v1 [diff against previous] re-posted go to this post
  3. v2 [diff against previous]
  4. v3 [diff against previous]
  5. v5 [diff against previous]
  6. v7 current [diff against previous]
  7. v8 [diff against previous]
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@xs4all.nl>
---
 fs/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/namei.c b/fs/namei.c
index b864aa426102..0cae8b4c071d 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4511,7 +4511,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.56.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help